Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.