Skip to content

Instantly share code, notes, and snippets.

@sostenesapollo
Last active November 9, 2023 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sostenesapollo/0009aa302a8cfc189d2bbe08d05c3fca to your computer and use it in GitHub Desktop.
Save sostenesapollo/0009aa302a8cfc189d2bbe08d05c3fca to your computer and use it in GitHub Desktop.
Get last day of month
function getDateLastDayOfMonth(date) {
    if (!date) return;

    const [year, month] = date.split('-');
    const lastDay = new Date(year, month, 0).getDate();

    // JavaScript months are 0-indexed
    return new Date(Date.UTC(year, month - 1, lastDay, 12));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment