Add minutes to date

JavaScript, Date · Nov 28, 2020

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

const addMinutesToDate = (date, n) => {
  const d = new Date(date);
  d.setTime(d.getTime() + n * 60000);
  return d.toISOString().split('.')[0].replace('T',' ');
};
addMinutesToDate('2020-10-19 12:00:00', 10); // '2020-10-19 12:10:00'
addMinutesToDate('2020-10-19', -10); // '2020-10-18 23:50:00'

More like this

  • Add days to date

    JavaScript, Date

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

  • Add weekdays to date

    JavaScript, Date

    Calculates the date after adding the given number of business days.

  • Days ago

    JavaScript, Date

    Calculates the date of n days ago from today as a string representation.