note 103333 deleted from function.date by danbrown

From: Date: Thu, 07 Apr 2011 18:16:17 +0000
Subject: note 103333 deleted from function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178612@lists.php.net to get a copy of this message
Note Submitter: Kolink ---- In response to "scorp at scorp dot ca" You can save a LOT of effort with this function instead: <?php // assuming connection to a MySQL server function add_months( $source, $months) { if( is_string($source)) $source = strtotime($source); $ret = mysql_fetch_array( mysql_query( "SELECT DATE_ADD( '".date("Y-m-d H:i:s",$source)."', INTERVAL ".$months." MONTH)")); return $ret[0]; } $start_date = "2011-01-31"; $list = Array(); for( $i=1; $i<=24; $i++) { $list[] = add_months( $start_date, $i); } print_r($list); ?>

« previous php.notes (#178612) next »