Menu

gitpiper

addDaysToDate javascript Code Snippet in 2024

dateintermediate

Last Updated: 8 April 2024

Calculates the date of n days from the given date, returning its string representation.

  • Use new Date() to create a date object from the first argument.
  • Use Date.prototype.getDate() and Date.prototype.setDate() to add n days to the given date.
  • Use Date.prototype.toISOString() to return a string in yyyy-mm-dd format.
const addDaysToDate = (date, n) => { const d = new Date(date); d.setDate(d.getDate() + n); return d.toISOString().split('T')[0]; };
addDaysToDate('2020-10-15', 10); // '2020-10-25' addDaysToDate('2020-10-15', -10); // '2020-10-05'

javascript snippet similar to addDaysToDate 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! ✌️