Gordon Werner Posted September 17, 2008 Share Posted September 17, 2008 Hi there ... how does one determine the following. I need to have a message pop up every 2nd tuesday ... and I need to be able to store this in advance. if I being with SEP09 ... how do I easily determine what # day is the 2nd tues in OCT or NOV, etc ... I cannot just add seconds from epoch because the # of the day will change from month to month Can anyone help? Thanks in advance Gordon Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/ Share on other sites More sharing options...
GingerRobot Posted September 17, 2008 Share Posted September 17, 2008 Try this: $month = 8; $year = 2008; $start_of_month = mktime(0,0,0,$month,1,$year); if(date('N',$start_of_month)==2){//first day of month is tuesday $second_tuesday = date('d-m-Y',$start_of_month+60*60*24*7); }else{ $second_tuesday = date('d-m-Y',strtotime('next tuesday',$start_of_month)+60*60*24*7); } echo $second_tuesday; Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644005 Share on other sites More sharing options...
HeaDmiLe Posted September 17, 2008 Share Posted September 17, 2008 <?php $tue = date('N',$timestamp); $day = date('d',$timestamp); if ( $tue == 2 && $day > 7 ) { // then it's sure that is the second week and day is tuesday ..more action.. } ?> from the head without testing... tell me if i'm wrong... i think it's better solution Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644007 Share on other sites More sharing options...
thesaleboat Posted September 17, 2008 Share Posted September 17, 2008 Best solution... double click on the clock in the lower right hand of your screen. Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644010 Share on other sites More sharing options...
HeaDmiLe Posted September 17, 2008 Share Posted September 17, 2008 Best solution... double click on the clock in the lower right hand of your screen. Ummm, interesting solution... Maybe i'll try to solve some of my problems on your way... Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644014 Share on other sites More sharing options...
Zane Posted September 17, 2008 Share Posted September 17, 2008 you can always enter a regular date into the strtotime function $whatDayWillitBNextYear = date("l", strtotime("Sep 17 2009")); echo $whatDayWillitBNextYear; $whatDayWillitBNextYear = date("l", strtotime("09/17/2030")); echo $whatDayWillitBNextYear; $whatDayWillitBNextYear = date("l", strtotime("9 17 2010")); echo $whatDayWillitBNextYear; $whatDayWillitBNextYear = date("l", strtotime("September 17th 2042")); echo $whatDayWillitBNextYear; Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644034 Share on other sites More sharing options...
HeaDmiLe Posted September 17, 2008 Share Posted September 17, 2008 Edit: <?php $tue = date('N',$timestamp); $day = date('d',$timestamp); if ( $tue == 2 && $day >= 7 ) { // then it's sure that is the second week and day is tuesday ..more action.. } ?> btw sry for new post, i saw edit icon after posting Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644041 Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 Here's another way: <?php for ($y=2008;$y<2011;$y++) for ($m=1;$m<13;$m++) { $sec_tues = (date('l',strtotime($y . '-' . $m . '-1')) == 'Tuesday')?date ('F jS, Y',strtotime('first tuesday',strtotime($y . '-' . $m . '-1'))):date ('F jS, Y',strtotime('second tuesday',strtotime($y . '-' . $m . '-1'))); echo $sec_tues.'<br>'; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644057 Share on other sites More sharing options...
Zane Posted September 17, 2008 Share Posted September 17, 2008 wouldn't this work in strtotime? strtotime("second tuesday in next month") Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644103 Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 No. I tried: <?php cho date('F jS, Y',strtotime("second tuesday in next month")); ?> and got December 31st, 1969 which is what you get when strtotime() doesn't recognize the date string. Ken Quote Link to comment https://forums.phpfreaks.com/topic/124686-how-do-you-find-dates-of-specific-days-of-the-week-in-the-future/#findComment-644132 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.