samoht Posted September 14, 2011 Share Posted September 14, 2011 Hello, I want to display a weekly events day and time. This event will always be on Saturday @ 10:45 am however, I want to output: 2011-09-17 10:45 then when that date is passed - I want it to change to the next Saturday: 2011-09-21 10:45 etc. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/ Share on other sites More sharing options...
Adam Posted September 14, 2011 Share Posted September 14, 2011 It's so easy it feels like cheating.. echo date('Y-m-d', strtotime('next saturday')) . ' 10:45AM'; Just be careful when using strtotime. Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/#findComment-1269194 Share on other sites More sharing options...
voip03 Posted September 14, 2011 Share Posted September 14, 2011 $nextWeek = time() + (7 * 24 * 60 * 60); // 7 days; 24 hours; 60 mins; 60secs echo 'Now: '. date('Y-m-d') ."\n"; echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n"; // or using strtotime(): echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) . ' 10:45AM'; Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/#findComment-1269197 Share on other sites More sharing options...
Adam Posted September 14, 2011 Share Posted September 14, 2011 voip03, that would output today's date and the date in a week's time. Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/#findComment-1269198 Share on other sites More sharing options...
voip03 Posted September 14, 2011 Share Posted September 14, 2011 voip03, that would output today's date and the date in a week's time. use the example to write the code Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/#findComment-1269199 Share on other sites More sharing options...
ManiacDan Posted September 14, 2011 Share Posted September 14, 2011 voip03, that would output today's date and the date in a week's time. use the example to write the code Your example says nothing about "saturday" at all, the example does not pertain to the question that was asked. OP: The strtotime solution is the best one, however, as he said, strtotime is a tricky beast. You may want to use: strtotime('+1 saturday') -Dan Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/#findComment-1269200 Share on other sites More sharing options...
samoht Posted September 14, 2011 Author Share Posted September 14, 2011 Thanks Guru! I thought it would be more complicated. What is the tricky stuff with strtotime() ? Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/#findComment-1269213 Share on other sites More sharing options...
ManiacDan Posted September 14, 2011 Share Posted September 14, 2011 Thanks Guru! I thought it would be more complicated. What is the tricky stuff with strtotime() ? Adam's name is Adam, his title is Guru ;-) The tricky stuff comes from the interpretations of "next" and "last". For instance, if I ask for "next wednesday" I get 7 days from now. If I ask for "thursday" or "next thursday" I get tomorrow. The definition of "next" for the computer is "the next occurring one." The definition of "next" in common parlance is "the one during next week." Sometimes strtotime produces results you don't expect, so I'd test this for a week's worth of days to make sure it always returns the right dates before releasing it. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/247124-echo-date-and-time-of-upcoming-event/#findComment-1269217 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.