note 69317 deleted from function.date by bobby

From: Date: Thu, 07 Sep 2006 18:24:06 +0000
Subject: note 69317 deleted from function.date by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116863@lists.php.net to get a copy of this message
Note Submitter: Nacho Cofré ---- This function returns the month before in YYYY-MM date format (date("Y-m")) given a month in that format. Useful for MySql querys construction. function month_before($year_month) { // YYYY-MM format $year = str_pad(substr($year_month, 0, 4), 4, "0", STR_PAD_LEFT); $month = str_pad(substr($year_month, 5, 2), 2, "0", STR_PAD_LEFT); switch ($month) { case "01": return ($year-1)."-12"; default: return $year."-".str_pad($month-1, 2, "0", STR_PAD_LEFT); } } You can make an array easily with: $months[0] = date("Y-m"); $i=0; while($months[$i] != BEGINNING_MONTH) { $i++; $months[$i] = month_before($meses[($i-1)]); }

« previous php.notes (#116863) next »