• Status: Solved
• Priority: Medium
• Security: Public
• Views: 136

# 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!
0
irene79
• 3
• 2
1 Solution

Commented:
(\$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" );
0

Commented:
(\$d,\$m,\$y)=(localtime time-30*24*60*60)[3,4,5];
\$m+=1; \$y+=1900;
\$old=sprintf"%04d%02d%02d",\$y,\$m,\$d;
print "\$mydate more than 30 days old\n" if( (join'',reverse split'/',\$mydate) lt \$old );
0

Author Commented:
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
0

Commented:
#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 );
0

Author Commented:
Thanks ozo! it works :)
0

## Featured Post

• 3
• 2
Tackle projects and never again get stuck behind a technical roadblock.