Hello, I want to match a date in the format day/month/year. where day is two digits month is two digits and year is four digits. Also, I want to check see if it is a valid date, for example knows when is leap year, and know which month has 30days, 31days and 28, or 29 days for Februrary.
+4
A:
Take a look at something like Date::Manip; there's little sense in doing this yourself when things like this are available.
$date = ParseDate($mydate);
unless ($date) {
# error
}
...
WhirlWind
2010-04-04 03:37:29
thanks, it seemed to work, for month/day/year formats but i am having trouble getting it to work for day/month/year formats.
Zerobu
2010-04-04 04:29:55
@Zerobu 10/12/2010 is ambiguous. Date::Manip assumes American style, October 12th. You have to tell it otherwise. See DateFormat in http://search.cpan.org/~sbeck/Date-Manip-5.56/lib/Date/Manip.pod#DATE::MANIP_VARIABLES for details.
Schwern
2010-04-04 05:31:37
+1
A:
use the following code
use strict;
use warnings;
use Date::Manip;
my $start="2010:03:30:23:02:3";
my $split=":";
my($year,$month,$date,$hour,$min,$sec);
($year,$month,$date,$hour,$min,$sec)=split($split,$start);
my $result = ParseDate("$month/$date/$year");
if(!$result)
{
print "Invalid Date\n";
exit;
}
muruga
2010-04-05 03:11:25