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

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
Asked:
irene79
  • 3
  • 2
1 Solution
 
ozoCommented:
($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
 
ozoCommented:
($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
 
irene79Author 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
 
ozoCommented:
#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
 
irene79Author Commented:
Thanks ozo! it works :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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