Jump to content

[SOLVED] Get Number Of Days


Daney11

Recommended Posts

Thanks again for your help.

 

   

   $date1 = strtotime(2009-03-12 12:27:00);
   $date2 = strtotime(2009-04-12 22:58:00);
   $dateDiff = $date1 - $date2;
   $daysRemaining = floor($dateDiff/(60*60*24));

 

Works, however im getting "-32 Days Remaining"

 

Im not sure where the "-" is coming from.

 

Edited, seen your edited version.

 

Thanks a lot

Hi

 

That is partly because of the order of the dates. Just put the most recent of the 2 date first when subtracting one from the other.

 

The other issue is that is usng the full date / times (which might well be what you want). So if you compared 23:59 on one day with 00:01 on the next day it is returning 120 second then dividing that by the number of seconds in a day and using floor which would return 0. In such a situation you might want to still return 1 day, in which case change it to:

 

   $date1 = strtotime(2009-04-12 22:58:00);
   $date2 = strtotime(2009-03-12 12:27:00);
   $daysRemaining = floor($date1/(60*60*24)) - floor($date2/(60*60*24));
[/code

(or rather than dividing by 60*68*24 you could just chop the time part off the date before passing it to strtime).

All the best

Keith

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.