Skip to content

Instantly share code, notes, and snippets.

@yeikos
Last active December 27, 2015 03:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yeikos/7257709 to your computer and use it in GitHub Desktop.
<?php
function strtotime_months($num, $timestamp = null) {
$num = (int)$num;
$timestamp = $timestamp ? (int)$timestamp : time();
$result = strtotime("last day of $num month", $timestamp);
// Si el día actual es superior al último día del mes resultante
return (date('d', $timestamp) > date('d', $result)) ?
// Nos quedamos con el último día del mes resultante
$result :
// De lo contrario nos quedamos con el día actual del mes resultante
strtotime("$num month", $timestamp);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment