note 110205 added to function.strtotime

From: Date: Sun, 30 Sep 2012 22:41:09 +0000
Subject: note 110205 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-191080@lists.php.net to get a copy of this message
Note that strtotime('09/30/2012') will have a time of 00:00:00. milespickens function _get_quarter fails when the current date matches the start or end of a quarterly period specified in the quarters array. To get around this is simply compare $today , $date1 and $date2 as date values (mm/dd/yyyy) in the if statement below. <?php function _get_quarter( $minus = NULL ) { //put correct begin dates and end dates in Bingo array $bingo = array(); $quarters = array( 1 => array( '01/01/', '03/31/'), 2 => array( '04/01/', '06/30/'), 3 => array( '07/01/', '09/30/'), 4 => array( '10/01/', '12/31/') ); if( $minus ) { $adjust = 3 * $minus; $today = strtotime($adjust . " months", time()); } else { $today = time(); } $year = date("Y", $today); foreach($quarters as $key => $val) { $date1 = strtotime($val[0] . $year); $date2 = strtotime($val[1] . $year); if ( (($todayD > $date1) && ($todayD < $date2)) || ((date("m/d/Y",$todayD) == (date("m/d/Y",$date1))) && ($todayD < $date2)) || (($todayD > $date1) && (date("m/d/Y",$todayD) == date("m/d/Y",$date2))) ) { $bingo[] = $quarters[$key][0] . $year; $bingo[] = $quarters[$key][1] . $year; } } return $bingo; } $this_quarter = $this->_get_quarter( NULL ); $last_quarter = $this->_get_quarter( -1 ); $next_quarter = $this->_get_quarter( 1 ); var_dump($this_quarter); var_dump($last_quarter); var_dump($next_quarter); ?> Results today (09/30/2012): array(2) { [0]=> string(10) "07/01/2012" [1]=> string(10) "09/30/2012" } array(2) { [0]=> string(10) "04/01/2012" [1]=> string(10) "06/30/2012" } array(2) { [0]=> string(10) "10/01/2012" [1]=> string(10) "12/31/2012" } ---- Server IP: 69.147.83.199 Probable Submitter: 208.124.232.94 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/110205 Del: integrated -- https://master.php.net/note/delete/110205/integrated Del: useless -- https://master.php.net/note/delete/110205/useless Del: bad code -- https://master.php.net/note/delete/110205/bad+code Del: spam -- https://master.php.net/note/delete/110205/spam Del: non-english -- https://master.php.net/note/delete/110205/non-english Del: in docs -- https://master.php.net/note/delete/110205/in+docs Del: other reasons-- https://master.php.net/note/delete/110205 Reject -- https://master.php.net/note/reject/110205 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191080) next »