Link to home
Start Free TrialLog in
Avatar of irene79
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!
Avatar of ozo
ozo
Flag of United States of America image

($d,$m,$y)=(localtime time-30*24*60*60)[3,4,5];
$m+=1; $y+=1900;

print "$mydate more than 30 days old\n" if( (join'',reverse split'/',$mydate) lt "$y$m$d" );
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of irene79
irene79

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)=(localtime 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 );
Avatar of irene79

ASKER

Thanks ozo! it works :)