Forum Moderators: coopster & phranque

Message Too Old, No Replies

Date Modifier

         

web_young

6:24 pm on Aug 29, 2004 (gmt 0)

10+ Year Member



Does anyone know if this is possible with perl? I want a user to be able to enter a date into a form in any common format (07/05/2004, 7/5/2004, 7/5/04). Then I want to print that date like this July 5, 2004. Can that be done with perl? Does anyone have a sample script that I could look at?

g1smd

7:10 pm on Aug 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How are you going to decide if 07/05/04 is:

July 5th 2004 or
7th May 2004 or
2007 May 04?

All of those are valid interpretations.

.

I would stick with the universally recognised ISO 8601 / RFC 3339 format; where today is 2004-08-29 for example.

See: [w3.org...]

web_young

8:53 pm on Aug 29, 2004 (gmt 0)

10+ Year Member



I would stick with the universally recognised ISO 8601 / RFC 3339 format; where today is 2004-08-29 for example.

Good point. So lets say the user inputs the date as 2004-08-29. Is there then a way for me to change and print the format to this: August 28, 2004

tombola

8:49 am on Aug 30, 2004 (gmt 0)

10+ Year Member



$user_input = "2004-08-28";

@month = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

$year = substr($user_input,0,4);
$month = substr($user_input,5,2);
$month =~ s/^0//;
$day = substr($user_input,8,2);

$your_output = "$months[$month-1] $day, $year";

Newbie77

9:07 pm on Sep 1, 2004 (gmt 0)

10+ Year Member



How would you write this to convert any numeric date to a string?
This is what I have to work with so far. I am completely stuck and don't even know where to start.

#!/usr/bin/perl
#date.cgi - converts a numeric date to a string
use CGI qw(:standard);
use strict;

#declare variables
my ($date);

#assign input item to variable
$date = param('Date');

#break date apart

#display date
print "Date: ";