Jackanape Posted September 12, 2007 Share Posted September 12, 2007 As usual, my lizard brain encounters significant obstacles when dealing with the intricacies of php, but in this case, I feel vindicated, as I'm finding the same problem throughout my searches, so it's not just me... I'm building a schedule script--well, modifying one I built last year--to add an event every second and third Sunday of the month. However, when I try to find that Sunday, and compare to my timestamp, I run into trouble: $myDays = getMyDays(); $keys = array_keys( $myDays['raw'] ); $keys = count($keys); for($s = 0; $s < $keys; $s++) { $schedday = date('l, F jS Y', $myDays['raw'][$s]); $frdays = date('l, F jS Y', strtotime("fifth sunday" ,$myDays['raw'][$s]) ); echo $frdays . $schedday; if ($schedday = $frdays) {echo 'everybody hold hands.';} } This seems to stem from the fact that strtotime() doesn't count the first occurence of the date...at least not the way I'm trying to find it. I've tried creating a new variable, and using that as my second strtotime parameter, but I get this error: strtotime() expects parameter 2 to be long, string given So, I'm baffled. I need to compare the Sunday in my array to the actual third Sunday of the month, right? But, I'm just not getting it... Any and all help is most humbly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/69062-solved-comparing-dates-with-strtotime-what-the-heck/ Share on other sites More sharing options...
Jackanape Posted September 12, 2007 Author Share Posted September 12, 2007 hmm...What I did was set up an if-else statement, that would change the day I was looking at, depending on the first day of the month. This may have been the long way to go about it--but at least I solved it!!! if ( date('w', strtotime("first day",$ts)) == 0) //$ts is my desired timestamp. I'm essentially saying if the first day of the month is a Sunday, then don't count it. { $frday10 = date('l, F jS Y', strtotime("third sunday" ,$ts) ); $frday50 = date('l, F jS Y', strtotime("fourth sunday" ,$ts) ); } else { $frday10 = date('l, F jS Y', strtotime("second sunday" ,$ts) ); $frday50 = date('l, F jS Y', strtotime("third sunday" ,$ts) ); } I can now use this on both a projected schedule and a current month's schedule, depending on how I want to use it. It may be rough and basic, but it works! Quote Link to comment https://forums.phpfreaks.com/topic/69062-solved-comparing-dates-with-strtotime-what-the-heck/#findComment-347254 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.