Forum Moderators: coopster

Message Too Old, No Replies

Difference in timestamps off due to leap year?

         

tresmom5

7:44 pm on Jan 16, 2008 (gmt 0)

10+ Year Member



I admit to being not very good at php. I am trying to just find out the difference between today's date and a future date in weeks and days in php.

$actual_timestamp = time();
$remaining_seconds = $future_timestamp - $actual_timestamp;
$remaining_days = floor($remaining_seconds / (60*60*24));

I used this and then divided the $remaining days/7 to get the weeks.

I am off a day due to leap year. How do I fix this?

coopster

9:14 pm on Jan 16, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you considered converting the dates to julian dates before performing the math? PHP has Calendar Functions [php.net] that you may find useful.
$actual_timestamp = time(); 
$remaining_days = unixtojd($future_timestamp) - unixtojd($actual_timestamp);
$remaining_weeks = floor($remaining_days/7);