Page 1 of 1

[SOLVED] strtotime next thursday returning a wednesday

Posted: Fri Dec 05, 2008 5:09 am
by deejay
if you were to run this code

Code: Select all

 
$text_day = 'Th';
$year = '2009';
$month = '10';
$day = '23';
 
if ( $text_day == 'Th' ){
$next_thursday = date('Y-m-d', strtotime("next Thursday", mktime(0,0,0,$month,$day,$year)));
echo $next_thursday.' <BR>';
return $next_thursday;
}
 
i get the result 2009-10-28
i make that a wednesday.

I have this code working in a loop that returns me a year full of thursdays. it works fine until it gets to this date.
Heres the result of that loop array
Array ( [0] => 2008-12-11 [1] => 2008-12-18 [2] => 2008-12-25 [3] => 2009-01-01 [4] => 2009-01-08 [5] => 2009-01-15 [6] => 2009-01-22 [7] => 2009-01-29 [8] => 2009-02-05 [9] => 2009-02-12 [10] => 2009-02-19 [11] => 2009-02-26 [12] => 2009-03-05 [13] => 2009-03-12 [14] => 2009-03-19 [15] => 2009-03-26 [16] => 2009-04-02 [17] => 2009-04-09 [18] => 2009-04-16 [19] => 2009-04-23 [20] => 2009-04-30 [21] => 2009-05-07 [22] => 2009-05-14 [23] => 2009-05-21 [24] => 2009-05-28 [25] => 2009-06-04 [26] => 2009-06-11 [27] => 2009-06-18 [28] => 2009-06-25 [29] => 2009-07-02 [30] => 2009-07-09 [31] => 2009-07-16 [32] => 2009-07-23 [33] => 2009-07-30 [34] => 2009-08-06 [35] => 2009-08-13 [36] => 2009-08-20 [37] => 2009-08-27 [38] => 2009-09-03 [39] => 2009-09-10 [40] => 2009-09-17 [41] => 2009-09-24 [42] => 2009-10-01 [43] => 2009-10-08 [44] => 2009-10-15 [45] => 2009-10-22 [46] => 2009-10-28 [47] => 2009-11-05 [48] => 2009-11-12 [49] => 2009-11-19 [50] => 2009-11-26 )
any ideas?? :banghead:

Re: strtotime next thursday returning a wednesday

Posted: Fri Dec 05, 2008 6:20 am
by mintedjo
Nothing wrong with the code. Works for me.
Maybe you have a buggy php :-P

But perhaps onion will post directly below me with a more informative answer... xD

Re: strtotime next thursday returning a wednesday

Posted: Fri Dec 05, 2008 6:21 am
by onion2k
Daylight savings time. mktime() has an optional boolean argument for it's last parameter to ignore it.

Re: strtotime next thursday returning a wednesday

Posted: Fri Dec 05, 2008 7:30 am
by deejay
Cheers all,

I've now checked on others servers I use and it's the only one it doesn't work on, so maybe something to do with the PHP install. version thats running on that one is 4.4.8.

Onion2k: if set the hour to say '6' wouldn't that cover any problems that may occur with the daylight saving, if so I have tried and still get the same problem.

Thanks for any help, much appreciated

Re: strtotime next thursday returning a wednesday

Posted: Sat Jan 10, 2009 10:11 am
by deejay
I don't supose anyone knows a fix for this problem.
I know that upgrading to php5 would sort my problem but I would have to update too many other pages ob the site.

I made a script that tests on all hours and DST parameter changes on the last parameter and still can't get it to work. Is there something simple I'm missing. :banghead:

Thanks for any help anyone can give.

Re: [SOLVED] strtotime next thursday returning a wednesday

Posted: Sun Jan 11, 2009 9:49 am
by deejay
its an ugly hack but 'last thursday' seems to work without return another dates except thursdays, so -

Code: Select all

 
$forward_date = date('Y-m-d', strtotime("+1 week", mktime(12,0,0,$month,$day,$year)));
$date_array = explode('-', $forward_date);
list($new_year,$new_month,$new_day) = $date_array;
    
$next_day = date('Y-m-d', strtotime("last Friday", mktime(12,0,0,$new_month,$new_day,$new_year)));
 
seems to work