Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  134] [ 7]  / answers: 1 / hits: 25704  / 10 Years ago, sun, november 23, 2014, 12:00:00

How do I get the smallest and biggest date. I see that the smallest number can be got like this:



Number.MIN_VALUE


Date does not have this. Is there a way to find the smallest and biggest date


More From » momentjs

 Answers
10

Date does not have this




Actually, it does, but only indirectly. According to the specification, a Date object's milliseconds-since-the-Epoch value can only be in the range -8640000000000000 to 8640000000000000.



So the minimum date is new Date(-8640000000000000) (Tue, 20 Apr -271821 00:00:00 GMT), and the maximum date is new Date(8640000000000000) (Sat, 13 Sep 275760 00:00:00 GMT).



If you wanted, you could put those on the Date function as properties:



Date.MIN_VALUE = new Date(-8640000000000000);
Date.MAX_VALUE = new Date(8640000000000000);


...but since Date instances are mutable, I probably wouldn't, because it's too easy to accidentally modify one of them. An alternative would be to do this:



Object.defineProperties(Date, {
MIN_VALUE: {
value: -8640000000000000 // A number, not a date
},
MAX_VALUE: {
value: 8640000000000000
}
});


That defines properties on Date that cannot be changed that have the min/max numeric value for dates. (On a JavaScript engine that has ES5 support.)


[#68728] Wednesday, November 19, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;