date difference

I have the following code which examines 2 dates

$cidate = mktime(0, 0, 0, $dayFrm, $monthFrm, $yearFrm);   
$codate = mktime(0, 0, 0, $dayTo, $monthTo, $yearTo);
$cidate = $yearFrm."-".$monthFrm."-".$dayFrm;
$date_diff = abs(strtotime(date($yearTo.'-'.$monthTo.'-'.$dayTo))-strtotime($cidate)) / 86400;

it then rounds off the dates into weeks

$getweeks = $date_diff / 7;
$weeks = ceil($getweeks);

it works fine until I put in 21st October 2008 to 28th October 2008
instead of returning 1 week its retrning 2

Anyone have any suggestions

The 21st of Oct 2008 and the the 28th Oct 2008 are Tuesdays. Since weeks start on Mondays (or Sundays, not sure) by default, PHP will consider the time between these dates to spread over two weeks.

But in every other month whether it be mon to mon, tue to tue and so on it returns 7 days

Okay, I ran some tests, and here’s what I’ve found out:
21 - 28 Oct 2008: 2 weeks (not really, it’s actually 1.005)
26 Oct - 2 Nov 2008: 2 weeks (same 1.005)
27 Oct - 3 Nov 2008: 1 week

The difference on the seconds level was exactly 3600: so there’s a one-hour overhead somewhere between Oct 26 and Oct 28 2008.
The ONLY thing I can think of, is Daylight Savings. You’re gonna have to verify that though.

On a sidenote: apologies for sounding as denigrating as I may have in my first post. I didn’t realize the problem ran this deep. I would also like to thank you for giving me this issue, as it’s been quite the challenge :) After looking into the daylight savings dates, it seems that DST shifts on Oct 26 2008, and adds another hour to the clock. I’m pretty sure PHP is including that extra hour in its calculations.

Thats it. DST in +1 on 26th October. Thanks for your help

Sponsor our Newsletter | Privacy Policy | Terms of Service