irene79
asked on
Date Comparison
I need to get the current date and compare with my database date. The format of my date is "dd/mm/yyyy". I will only need to retrieve out data which are more than 30 days. It's best not to use modules for this problem i have. Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what's the $mydate? is it the date that i retrieve from the database? the date retrieve out from the database when i print it out , is in this format "1999-10-27 00.00.00" please advice
#Sorry, I thought you said $mydate was in the format dd/mm/yyyy
($S,$M,$H,$d,$m,$y)=(local time time-30*24*60*60);
$m+=1; $y+=1900;
$old = sprintf "%04d-%02d-%02d %02d.%02d.%02d",$y,$m,$d,H ,$M,$S;
print "$mydate more than 30 days old\n" if( $mydate lt $old );
($S,$M,$H,$d,$m,$y)=(local
$m+=1; $y+=1900;
$old = sprintf "%04d-%02d-%02d %02d.%02d.%02d",$y,$m,$d,H
print "$mydate more than 30 days old\n" if( $mydate lt $old );
ASKER
Thanks ozo! it works :)
$m+=1; $y+=1900;
print "$mydate more than 30 days old\n" if( (join'',reverse split'/',$mydate) lt "$y$m$d" );