RE: [PHP-GTK] date functions

From: Date: Sun, 19 May 2002 03:46:50 +0000
Subject: RE: [PHP-GTK] date functions
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-2025@lists.php.net to get a copy of this message
I think this is off topic for this list, probably should go to php-general list, anyway; I use a routine that gives me Mondays for the next few weeks and past weeks. It may give you some ideas on how to tackle this. (And for the gurus out there, feel free to show me how to do this the correct/elegant way in a single line :-). The manual is very good particularly the version with user comments. http://www.php.net/manual/en/ref.datetime.php I bet if you had a look you would probably find a solution to your problem; HTH Andrew Braund <?php // returns array of dates corresponding to the next three // Mondays, tomorrow and the past nine Mondays function getWeekEnding(){ // adjust now (current) day of week from week ending Saturday to week ending Monday $nowDayofWeekM = date('w') - 2; if( $nowDayofWeekM < 0 ){ $nowDayofWeekM = 7 + $nowDayofWeekM; } $nowMonth = date('m'); $nowYear = date('Y'); $nowDayofMonth = date('j'); $mondayAry = array( 'forward_three_mondays','forward_two_mondays','next_monday', 'last_monday', 'back_two_mondays','back_three_mondays', 'back_four_mondays','back_five_mondays','back_six_mondays', 'back_seven_mondays','back_eight_mondays','back_nine_mondays' ); $offset = 20; // three Mondays ahead foreach( $mondayAry as $aMonday ){ $mondayAry[$aMonday] = mktime(0,0,0,$nowMonth,($nowDayofMonth-$nowDayofWeekM)+$offset,$nowYear); $offset -= 7; // move to previous Monday } // throw in tomorrow for good measure $mondayAry['tomorrow'] = mktime(0,0,0,$nowMonth,$nowDayofMonth+1,$nowYear); return $mondayAry; } $wE=getWeekEnding(); echo 'Tomorrows date is '.date('j/n/y',$wE['tomorrow']); echo ' ahead three Mondays is'. date('j/n/y',$wE['forward_three_mondays']); echo ', five Mondays ago was '. date('j/n/y',$wE['back_five_mondays']); ?> > -----Original Message----- > From: Josh Edwards [mailto:josho@tpg.com.au] > Sent: Sunday, 19 May 2002 09:51 > To: php-gtk-general@lists.php.net > Subject: [PHP-GTK] date functions > > > Does anyone know a good way to count the days between two dates. ie how > many Mondays fall between two dates. I have the start and end dates and the > no of days b/w them.

« previous php.gtk.general (#2025) next »