Menu

gitpiper

lastDateOfMonth javascript Code Snippet in 2024

dateintermediate

Last Updated: 22 April 2024

Returns the string representation of the last date in the given date's month.

  • Use Date.prototype.getFullYear(), Date.prototype.getMonth() to get the current year and month from the given date.
  • Use the new Date() constructor to create a new date with the given year and month incremented by 1, and the day set to 0 (last day of previous month).
  • Omit the argument, date, to use the current date by default.
const lastDateOfMonth = (date = new Date()) => { let d = new Date(date.getFullYear(), date.getMonth() + 1, 0); return d.toISOString().split('T')[0]; };
lastDateOfMonth(new Date('2015-08-11')); // '2015-08-30'

javascript snippet similar to lastDateOfMonth For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️