Moon-Man.net Posted July 23, 2006 Share Posted July 23, 2006 Hello,I have a piece of code that is used to select each week's starting date and ending date for a PostgreSQL report. The dates must be starting (Monday) and ending (sunday) for each week in the given month of the given year. ($view_month & $view_year) This workes for EVERY month EXCEPT febuary. where it skips a month. Could some one please give me a hand?Ive been killing myslef over it all weekend/last week :(Cheers,Nathan[code]<?PHP$view_month = 2 ;// Febuary$view_year = 2005 ; // 2--5$end_date = date('t', mktime(0, 0, 0, $view_month, 0, $view_year)) ;echo "<select name='view_day'>" ;$prvMonth = $view_month - 1 ;$prvMthName = date('M', mktime(0, 0, 0, $prvMonth, 1, $view_year)) ;$prvMthDay = date('t', mktime(0, 0, 0, $prvMonth, 1, $view_year)) ;for ($i = $prvMthDay - 6; $i < $prvMthDay + 1; $i++){ echo "<option value='$i'>i == $i\n" ; echo date('D', mktime(0, 0, 0, $prvMonth, $i, $view_year)) ; if (date('D', mktime(0, 0, 0, $prvMonth, $i, $view_year)) == "Mon" ){ // Put into Select Box $startDay = date('dS F', mktime(0, 0, 0, $prvMonth, $i, $view_year)) ; $endDay = date('dS', mktime(0, 0, 0, $view_month, $i + 7, $view_year)) ; $work_date = date('F Y', mktime(0, 0, 0, $view_month, $i, $view_year)) ; }}// 2. Do the month requestedfor ($i=1; $i < $end_date; $i++){ if (date('D', mktime(0, 0, 0, $view_month, $i, $view_year)) == "Mon" ){ // Put into Select Box $startDay = date('dS', mktime(0, 0, 0, $view_month, $i, $view_year)) ; $endDay = date('dS', mktime(0, 0, 0, $view_month, $i + 6, $view_year)) ; $work_date = date('F Y', mktime(0, 0, 0, $view_month, $i, $view_year)) ; if ($endDay > $startDay) { echo "<option value='$i'>$startDay to $endDay $work_date\n" ; } }}echo "</select>";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/ Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Author Share Posted July 24, 2006 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-62592 Share on other sites More sharing options...
Barand Posted July 24, 2006 Share Posted July 24, 2006 Any use[code]<?php$view_month = 2 ;// Febuary$view_year = 2005 ; // 2--5$first = mktime (0,0,0,$view_month, 1, $view_year);$last = date('t', $first);$wks = ceil($last/7);$dow1 = (date('w', $first)+6)%7;$mon = strtotime ("-$dow1 days", $first);echo "<select name='view_day'>\n";for ($i=1; $i<=$wks; $i++) { $sun = strtotime ('+6 days', $mon); printf ("<OPTION value='$i'>%s to %s</OPTION>\n", date('jS', $mon), date('jS F Y', $sun)); $mon = strtotime ('+7 days', $mon); }echo '<select>';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-62663 Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Author Share Posted July 24, 2006 That would be perfect, but how does the %s work ETC? And how can i get it to show the brevious month's name? Eg in the provious code it has:[quote]30th January to Febuary 5th6th to 12th January13th to 19th January[/quote]And also the starting date as the select option.Cheers,Nathan Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-63177 Share on other sites More sharing options...
Barand Posted July 24, 2006 Share Posted July 24, 2006 [quote]but how does the %s work[/quote]http://www.php.net/sprintf[quote]how can i get it to show the brevious month's name?[/quote]You could try this if prefered[code]printf ("<OPTION value='$i'>%s to %s</OPTION>\n", date('jS M', $mon), date('jS M Y', $sun));[/code][quote]And also the starting date as the select option.[/quote]??? Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-63178 Share on other sites More sharing options...
Moon-Man.net Posted July 24, 2006 Author Share Posted July 24, 2006 Thanks, that seems easier then the way i was doing it.By the select name as the start date. i mean[code]<option value='<FIRST DAY OF WEEK START>' > WHAT EVER!!!</select>[/code]Cheers,Nathan Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-63181 Share on other sites More sharing options...
Moon-Man.net Posted July 25, 2006 Author Share Posted July 25, 2006 Ok, i got that! But it only works for 2005...What about 2006/2007/2008/2009...Cheers,Nathan Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-63199 Share on other sites More sharing options...
Barand Posted July 25, 2006 Share Posted July 25, 2006 [quote author=Moon-Man.net link=topic=101602.msg402957#msg402957 date=1153790826]Ok, i got that! But it only works for 2005...What about 2006/2007/2008/2009...Cheers,Nathan[/quote]For those years you will have to change the value of the $view_year variable Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-63289 Share on other sites More sharing options...
Moon-Man.net Posted July 26, 2006 Author Share Posted July 26, 2006 Lol, i know that! But the week Starting and Week Ending dates are all up the duff...D/W i fixed it anywho. Quote Link to comment https://forums.phpfreaks.com/topic/15431-week-starting-and-ending-dates/#findComment-63740 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.