How to get minimum and maximum date in JavaScript?

Sometimes, we want to get minimum and maximum date in JavaScript.

In this article, we’ll look at how to get minimum and maximum date in JavaScript.

How to get minimum and maximum date in JavaScript?

To get minimum and maximum date in JavaScript, the can use the timestamps for the min and max date in milliseconds.

For instance, we write

let maxDate = new Date(8640000000000000);
let minDate = new Date(-8640000000000000);

to use 8640000000000000 milliseconds since epoch as the max date timestamp.

Then we can pass that to the Date constructor to create a date object.

Likewise, we use -8640000000000000 milliseconds since epoch as the max date timestamp.

And then we create the Date object from it the same way.

Conclusion

To get minimum and maximum date in JavaScript, the can use the timestamps for the min and max date in milliseconds.