note 103333 added to function.date

From: Date: Thu, 07 Apr 2011 17:54:23 +0000
Subject: note 103333 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-178611@lists.php.net to get a copy of this message
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); ?> ---- Server IP: 109.169.40.147 Probable Submitter: 139.184.30.132 (proxied: 139.184.222.67) ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/103333 Del: integrated -- https://master.php.net/note/delete/103333/integrated Del: useless -- https://master.php.net/note/delete/103333/useless Del: bad code -- https://master.php.net/note/delete/103333/bad+code Del: spam -- https://master.php.net/note/delete/103333/spam Del: non-english -- https://master.php.net/note/delete/103333/non-english Del: in docs -- https://master.php.net/note/delete/103333/in+docs Del: other reasons-- https://master.php.net/note/delete/103333 Reject -- https://master.php.net/note/reject/103333 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178611) next »