Skip to content

First day/last day of month given a YYYY-MM-DD date


function first_day_of_month($yyyy_mm_dd = '2020-01-01', $strtotime = FALSE)
{
$first_day = date("Y-m-d", strtotime("+1 day", strtotime(date("Y-m-t", strtotime("-1 month" , strtotime($yyyy_mm_dd))))));
return ($strtotime)? strtotime($first_day): $first_day;
}

function last_day_of_month($yyyy_mm_dd = '2020-01-01', $strtotime = FALSE)
{
$last_day = date("Y-m-t", strtotime($yyyy_mm_dd));
return ($strtotime)? strtotime($last_day): $last_day;
}