Connecting Tech Pros Worldwide Forums | Help | Site Map

Comparing Dates

Newbie
 
Join Date: Jul 2008
Posts: 19
#1: Jul 4 '08
i need to send mail 1 month before expirydate stored in database to a client..till now i can just compare the dates by converting them using strtotime.is there anyways to find out many days are left till expirydate.



Member
 
Join Date: Jun 2007
Posts: 47
#2: Jul 4 '08

re: Comparing Dates


Hi bips

here it is what I understood you want to do

Expand|Select|Wrap|Line Numbers
  1. //considering this date is being fetch from db and was stored in this format
  2. $date = "2008-07-15 22:15:58"; 
  3.  
  4. $date1 = substr($date, 0, 11); 
  5.  
  6. $date2 = date("Y-m-d"); // current date
  7.  
  8. $difference = abs(strtotime($date2) - strtotime($date1));
  9.  
  10. $days = round(((($difference/60)/60)/24), 0); //remaining days
  11.  
$date is the expiry date, $date2 is the current date and $days is the total no. of days left till the expiry date.
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#3: Jul 4 '08

re: Comparing Dates


How are you doing that, if you can show some code?
Newbie
 
Join Date: Jul 2008
Posts: 19
#4: Jul 4 '08

re: Comparing Dates


Quote:

Originally Posted by hsriat

How are you doing that, if you can show some code?

thank you i finally made the code worked

Expand|Select|Wrap|Line Numbers
  1. $chexpiraton = strtotime($expiration);
  2.  
  3.      $today = date("Y-m-d");
  4.      $chtoday = strtotime($today);
  5.     $diff = $chexpiraton - $chtoday;
  6.     $noday = $diff / (24*60*60);
  7.  
$expiration contains date from the database;
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#5: Jul 4 '08

re: Comparing Dates


Quote:

Originally Posted by bips2005

thank you i finally made the code worked

Expand|Select|Wrap|Line Numbers
  1. $chexpiraton = strtotime($expiration);
  2.  
  3.      $today = date("Y-m-d");
  4.      $chtoday = strtotime($today);
  5.     $diff = $chexpiraton - $chtoday;
  6.     $noday = $diff / (24*60*60);
  7.  
$expiration contains date from the database;

What format is $expiration?.. If its simple UNIX time stamp, then subtract 30*24*60*60 from it and compare it with 'sec' index of gettimeofday array.
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#6: Jul 4 '08

re: Comparing Dates


Quote:

Originally Posted by hsriat

What format is $expiration?.. If its simple UNIX time stamp, then subtract 30*24*60*60 from it and compare it with 'sec' index of gettimeofday array.

See his post above. He's already got it to work correctly.
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#7: Jul 4 '08

re: Comparing Dates


Quote:

Originally Posted by r035198x

See his post above. He's already got it to work correctly.

Oh, thanks for that :)
Reply


Similar PHP bytes