Jump to content


Photo

Week starting and Ending dates.


  • Please log in to reply
8 replies to this topic

#1 Moon-Man.net

Moon-Man.net
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 23 July 2006 - 11:32 PM

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

<?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 requested
for ($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>";


#2 Moon-Man.net

Moon-Man.net
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 July 2006 - 12:48 AM

Anyone?


#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 24 July 2006 - 05:55 AM

Any use

<?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>';
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 Moon-Man.net

Moon-Man.net
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 July 2006 - 11:27 PM

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:

30th January to Febuary 5th
6th to 12th January
13th to 19th January


And also the starting date as the select option.
Cheers,
Nathan

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 24 July 2006 - 11:34 PM

but how does the %s work

http://www.php.net/sprintf

how can i get it to show the brevious month's name?

You could try this if prefered
printf ("<OPTION value='$i'>%s to %s</OPTION>\n", date('jS M', $mon), date('jS M Y', $sun));

And also the starting date as the select option.

???
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 Moon-Man.net

Moon-Man.net
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 24 July 2006 - 11:59 PM

Thanks, that seems easier then the way i was doing it.
By the select name as the start date. i mean

<option value='<FIRST DAY OF WEEK START>' > WHAT EVER!!!</select>
Cheers,
Nathan

#7 Moon-Man.net

Moon-Man.net
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 25 July 2006 - 01:27 AM

Ok, i got that! But it only works for 2005...What about 2006/2007/2008/2009...
Cheers,
Nathan

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 25 July 2006 - 08:50 AM

Ok, i got that! But it only works for 2005...What about 2006/2007/2008/2009...
Cheers,
Nathan

For those years you will have to change the value of the $view_year variable
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#9 Moon-Man.net

Moon-Man.net
  • Members
  • PipPipPip
  • Advanced Member
  • 84 posts

Posted 26 July 2006 - 12:06 AM

Lol, i know that! But the week Starting and Week Ending dates are all up the duff...
D/W i fixed it anywho.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users