note 108269 deleted from function.strtotime by aharvey

From: Date: Mon, 29 Oct 2012 02:02:57 +0000
Subject: note 108269 deleted from function.strtotime by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-191573@lists.php.net to get a copy of this message
Note Submitter: milespickens at gmail dot com ---- I need to get the Beginning and End dates of the Current Business Quarter, Past Business Quarters and Future Business Quarters. Here is a function which returns the dates in an array <?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( ($today > $date1) && ($today < $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 (4/12/2012): array(2) { [0]=> string(10) "04/01/2012" [1]=> string(10) "06/30/2012" } array(2) { [0]=> string(10) "01/01/2012" [1]=> string(10) "03/31/2012" } array(2) { [0]=> string(10) "07/01/2012" [1]=> string(10) "09/30/2012" }

« previous php.notes (#191573) next »