note 69317 added to function.date

From: Date: Thu, 31 Aug 2006 11:06:54 +0000
Subject: note 69317 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-116540@lists.php.net to get a copy of this message
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)]); } ---- Server IP: 64.71.164.2 Probable Submitter: 62.15.128.103 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/69317 Del: integrated -- https://master.php.net/note/delete/69317/integrated Del: useless -- https://master.php.net/note/delete/69317/useless Del: bad code -- https://master.php.net/note/delete/69317/bad+code Del: spam -- https://master.php.net/note/delete/69317/spam Del: non-english -- https://master.php.net/note/delete/69317/non-english Del: in docs -- https://master.php.net/note/delete/69317/in+docs Del: other reasons-- https://master.php.net/note/delete/69317 Reject -- https://master.php.net/note/reject/69317 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116540) next »