Skip to content

Instantly share code, notes, and snippets.

@mishudark
Created December 1, 2010 02:04
Show Gist options
  • Save mishudark/722802 to your computer and use it in GitHub Desktop.
Save mishudark/722802 to your computer and use it in GitHub Desktop.
devuelve el año y mes correctos al restar meses
<?php
/* date_correct.php
Copyright 2010 mishudark <mishudark@astrata.com.mx> <moonsadly@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
sirve para cuando vas restando meses al mes actual, ejem:
2010-09 - 15 meses;
restamos los meses: 09 - 15 = -6, ese -6 lo mandamos, junto con el año:
list($year,$month) = date_correct(2010,-6);
*/
function date_correct($year,$month){
if($month < 1){
$lessYear = floor( ($month-12)/-12 );
$year -= $lessYear;
$s = abs($month) % 12; //meses q se restaran a diciembre
$month = 12-$s;
}
return array($year,$month);//retorna año y mes
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment