Harsha M V
Harsha M V

Reputation: 54989

moment() Get todays date with midnight

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

Upvotes: 3

Views: 3428

Answers (1)

Tushar Gupta
Tushar Gupta

Reputation: 15943

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>

Upvotes: 5

Related Questions