Home > front end >  moment() Get todays date with midnight
moment() Get todays date with midnight

Time:09-17

I am trying to query the database with all records which are starting from today and greater than midnight.

var dateTime = moment().toDate();

gives me the current date and time. But is there any way to set the midnight of today?

new Date(new Date().setHours(0, 0, 0, 0))

Tried the above but still it give me

2021-09-11T18:30:00.000Z

CodePudding user response:

how about

moment().startOf('day').toString();

var now = moment().startOf('day').toString();
console.log(now);
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"></script>

  • Related