Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shreesubhendu/f9ada64f165fc69c0786339d59d2c79f to your computer and use it in GitHub Desktop.
Save shreesubhendu/f9ada64f165fc69c0786339d59d2c79f to your computer and use it in GitHub Desktop.
Last day of given month and year and last day of previous month in PHP
$current_month = 3;
$current_year = 2020;
//first day of previous month from given month and year
$firstDayOfLastMonth = date_create($current_year.'-'.$current_month.'-01 first day of last month')->format('Y-m-d');
//last day of previous month from given month and year
$lastDayOfLastMonth = date_create($current_year.'-'.$current_month.'-01 last day of last month')->format('Y-m-d');
//first day of given month and year
$firstDayOfCurrentMonth = date("Y-m-d",strtotime($current_year.'-'.$current_month.'-01'));
//last day of given month and year
$lastDayOfCurrentMonth = date("Y-m-t",strtotime($current_year.'-'.$current_month.'-01'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment