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 152 views
1 answer 140 views
1 answer 136 views
2 answers 138 views
1 answer 160 views
1 answer 127 views
1 answer 131 views
131 views asked Mar 21, 2022 by avibootz
...