jeff5656 Posted May 12, 2008 Share Posted May 12, 2008 How do I write something that will POST the date of the next available friday. It will look at today's date and see that it's monday, 5/12/08 and it will then POST "5/16/08"? Thanks. Link to comment https://forums.phpfreaks.com/topic/105267-solved-date-question/ Share on other sites More sharing options...
BlueSkyIS Posted May 12, 2008 Share Posted May 12, 2008 here is some code i use to get the next monday. maybe you can alter it for your use: // Day of the week, 0-6, Sun-Sat $now_array = getdate($yourdateinseconds); $wday = $now_array["wday"]; // Number of days back to the Monday to be displayed: switch ($wday) { case 0: { $daysBack = 6; $daysForward = 0; break; } case 1: { $daysBack = 0; $daysForward = 6; break; } case 2: { $daysBack = 1; $daysForward = 5; break; } case 3: { $daysBack = 2; $daysForward = 4; break; } case 4: { $daysBack = 3; $daysForward = 3; break; } case 5: { $daysBack = 4; $daysForward = 2; break; } case 6: { $daysBack = 5; $daysForward = 1; break; } } // Subtract daysBack to get the start date for this calendar $monTime = mktime($now_array["hours"],$now_array["minutes"],$now_array["seconds"],$now_array["mon"],$now_array["mday"]-$daysBack,$now_array["year"]); $endTime = mktime($now_array["hours"],$now_array["minutes"],$now_array["seconds"],$now_array["mon"],$now_array["mday"]- $daysBack + 6,$now_array["year"]); $monTime is the previous Monday, in seconds. $endTime is the following Sunday, in seconds. Link to comment https://forums.phpfreaks.com/topic/105267-solved-date-question/#findComment-539016 Share on other sites More sharing options...
kenrbnsn Posted May 12, 2008 Share Posted May 12, 2008 You can use a combination of the date() and strtotime() function: <?php $next_friday = date('n/d/Y',strtotime('next friday'); echo $next_friday; ?> Ken Link to comment https://forums.phpfreaks.com/topic/105267-solved-date-question/#findComment-539027 Share on other sites More sharing options...
jeff5656 Posted May 12, 2008 Author Share Posted May 12, 2008 Thanks to both - Ken's was way simpler so I used that! Link to comment https://forums.phpfreaks.com/topic/105267-solved-date-question/#findComment-539069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.