smugford2 Posted April 6, 2010 Share Posted April 6, 2010 I have a simple calendar with a repeating event on specific weekdays repeat every monday repeat every thursday etc etc The specific issue that i'm having is the following code works for everything except the first day of the month. $cMonth = "april"; $cYear = "2010"; $thu_counter = (int) date("d", strtotime("first thursday ".$cMonth." ".$cYear)); The expected result should be 1 (for Thursday april first 2010) The result that i'm getting is 8 (or Thursay April Eighth 2010) I've moved the calendar ahead one month and tested it for may as well and I have the same issue. $cMonth = "may"; $cYear = "2010"; $sat_counter = (int) date("d", strtotime("first saturday ".$cMonth." ".$cYear)); echo $sat_counter; expected result 1 actual result 8 any thoughts Thanks in Advanced Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/ Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month would incorrectly add one week to the returned timestamp. This has been corrected in 5.2.7 and later versions. Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/#findComment-1037871 Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 NOTE: For grins, I just tested this on my installation (5.2.12) and the bug still seems to be present. It still returns 8. Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/#findComment-1037877 Share on other sites More sharing options...
smugford2 Posted April 6, 2010 Author Share Posted April 6, 2010 from my php info page -- PHP Version 5.3.1 is it possible this but still exists? Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/#findComment-1037893 Share on other sites More sharing options...
Pikachu2000 Posted April 6, 2010 Share Posted April 6, 2010 It seems so. I wrote a quick workaround for it, maybe you could incorporate it into a function and use it. $occurrence = 'first'; $day_name = 'thursday'; $month = 'April'; $year = 2010; $date = (int) date("d", strtotime($occurrence . " " . $day_name . " " . $month . " " . $year)); if( $occurrence == 'first' && $date >= 8 ) { $date -= 7; } echo $date; Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/#findComment-1037906 Share on other sites More sharing options...
smugford2 Posted April 6, 2010 Author Share Posted April 6, 2010 works perfectly in my function THANKS!! Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/#findComment-1037919 Share on other sites More sharing options...
smugford2 Posted April 6, 2010 Author Share Posted April 6, 2010 I have a simple calendar with a repeating event on specific weekdays repeat every monday repeat every thursday etc etc The specific issue that i'm having is the following code works for everything except the first day of the month. $cMonth = "april"; $cYear = "2010"; $thu_counter = (int) date("d", strtotime("first thursday ".$cMonth." ".$cYear)); The expected result should be 1 (for Thursday april first 2010) The result that i'm getting is 8 (or Thursay April Eighth 2010) I've moved the calendar ahead one month and tested it for may as well and I have the same issue. $cMonth = "may"; $cYear = "2010"; $sat_counter = (int) date("d", strtotime("first saturday ".$cMonth." ".$cYear)); echo $sat_counter; expected result 1 actual result 8 any thoughts Thanks in Advanced Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/#findComment-1037920 Share on other sites More sharing options...
jcbones Posted April 6, 2010 Share Posted April 6, 2010 Try it like this: $month = 'april'; $year = 2010; echo date('d',strtotime('+0 week thursday ' . $month . ' ' . $year)); Quote Link to comment https://forums.phpfreaks.com/topic/197769-first-day-of-the-month-strtotime-issue/#findComment-1038043 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.