focus72050 Posted September 4, 2006 Share Posted September 4, 2006 Hi everyone, I am looking for php code that will return to me whether it is the first, second third or if exists fourth wednesday for the current month, and by current month the script should decide on its own what the current month is.Thank you in advance really appreciate it. Link to comment https://forums.phpfreaks.com/topic/19648-caculate-what-wednesday-is-it-of-the-month/ Share on other sites More sharing options...
extrovertive Posted September 4, 2006 Share Posted September 4, 2006 [code=php:0]$weekposA = array(1=>"first", "second", "third", "fourth");$month = date("F"); //get the month (Januaray to December)$day = date("j"); //get day of the week 1-31$weekpos = ceil($day/7); //determine whether it's the 1st, 2nd, ...of the week$theweeknum = $weekposA[$weekpos];$todayweek = date("l");//if($todayweek == "Wednesday")echo "Today is the " . $theweeknum . " " . $todayweek . " of " . $month;[/code]To make it display on Wednesday's only, just uncomment my "if($todayweek == "Wednesday")" out. Link to comment https://forums.phpfreaks.com/topic/19648-caculate-what-wednesday-is-it-of-the-month/#findComment-85588 Share on other sites More sharing options...
AndyB Posted September 4, 2006 Share Posted September 4, 2006 There are always at least four Wednesdays in a month. Sometimes there are five. Link to comment https://forums.phpfreaks.com/topic/19648-caculate-what-wednesday-is-it-of-the-month/#findComment-85689 Share on other sites More sharing options...
obsidian Posted September 4, 2006 Share Posted September 4, 2006 to rework extrovertive's response slightly, all you'd have to do to find out which occurrence of the day of the week a certain date is, just run a function like this where you can pass the date to it. then, you've got a very flexible solution that you can use the results in a variety of ways:[code]<?phpfunction getWhichWeek($date = '') { $date = empty($date) ? date('Y-m-d') : $date; // default to today list($year, $month, $day) = explode('-', $date); $res = array( 'day' => date('l', strtotime($date)), 'week' => ceil($day/7) ); switch($res['week']) { case 1: $res['post'] = 'st'; break; case 2: $res['post'] = 'nd'; break; case 3: $res['post'] = 'rd'; break; default: $res['post'] = 'th'; } return $res;}$today = getWhichWeek();echo "Today is the {$today['week']}{$today['post']} {$today['day']} of the month!";?>[/code]have fun with that! Link to comment https://forums.phpfreaks.com/topic/19648-caculate-what-wednesday-is-it-of-the-month/#findComment-85717 Share on other sites More sharing options...
focus72050 Posted September 5, 2006 Author Share Posted September 5, 2006 Everyone thank you a million, I really appreciate it. And yes you are correct there are at least 4 of each day in a month, dont know what I was thinking. Link to comment https://forums.phpfreaks.com/topic/19648-caculate-what-wednesday-is-it-of-the-month/#findComment-86164 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.