note 101156 deleted from function.date by tularis

From: Date: Thu, 09 Feb 2012 20:52:47 +0000
Subject: note 101156 deleted from function.date by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185966@lists.php.net to get a copy of this message
Note Submitter: vlado dot nikolchev at gmail dot com ---- Simple and handy function that offsets a MySQL formatted date and returns the new correctly formatted date <?php /** * * @param string $dt // MySQL formatted date (like 2010-01-01) * @param int $year_offset // like 2 or -2, or 5 or -5 ... * @param int $month_offset // like 2 or -2, or 5 or -5 ... * @param in $day_offset // like 2 or -2, or 5 or -5 ... * @return string // the new MySQL formatted date (like 2009-07-01) */ function MySQLDateOffset($dt,$year_offset='',$month_offset='',$day_offset='') { return ($dt=='0000-00-00') ? '' : date ("Y-m-d", mktime(0,0,0,substr($dt,5,2)+$month_offset,substr($dt,8,2)+ $day_offset,substr($dt,0,4)+$year_offset)); } ?> Examples: <?php echo MySQLDateOffset('2010-06-01',2,5,15); // will return 2012-11-16 echo MySQLDateOffset('2010-06-01',-6,5,38); // will return 2004-12-09 ?>

« previous php.notes (#185966) next »