This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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