How to subtract hours from a date in Node.js

1 Answer

0 votes
function subtractHoursFromDate(hours, date = new Date()) {
  	date.setHours(date.getHours() - hours);

  	return date;
}

const date = new Date('2022-03-20T18:37:24');

console.log(subtractHoursFromDate(5, date).toString());





/*
run:

Sun Mar 20 2022 13:37:24 GMT+0000 (Coordinated Universal Time)

*/

 



answered Mar 17, 2022 by avibootz

Related questions

1 answer 143 views
1 answer 132 views
1 answer 128 views
2 answers 129 views
1 answer 151 views
1 answer 120 views
1 answer 125 views
125 views asked Mar 21, 2022 by avibootz
...