How to get the beginning and end of the day in JavaScript

1 Answer

0 votes
function getStartOfDay(date = new Date()) {
  return new Date(date.setHours(0, 0, 0, 0));
}


function getEndOfDay(date = new Date()) {
  return new Date(date.setHours(23, 59, 59, 999));
}


console.log(getStartOfDay(new Date())); 

console.log(getEndOfDay(new Date())); 




/*
run:

2025-12-12T00:00:00.000Z
2025-12-12T23:59:59.999Z

*/


 



answered Dec 12, 2025 by avibootz
...