I noticed Date.Parse
can't handle only 2 digits dates.
Say I have this
mm/dd/yy = 7/11/20
Date parse will think it is = 7/11/1920
. Can you set it to use the year two thousand? Like it's kinda weird I got the jquery u.i date picker and if you type in 7/11/20
it will figure out 2020
.
So it would be nice if Date.parse
could keep up I rather have them both not know what is going on or both know what is going on then have one that knows and one that does not know.
If the DATEPARSE function is not available for the data that you're working with, or the field you are trying to convert is a number data type, you can use the DATE function instead. The DATE function converts a number, string or date expression to a date type.
The parse() method takes a date string (such as "2011-10-10T14:48:00" ) and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. This function is useful for setting date values based on string values, for example in conjunction with the setTime() method and the Date object.
Approach 1: Define two dates using new Date(). Calculate the time difference of two dates using date2.getTime() – date1.getTime(); Calculate the no. of days between two dates, divide the time difference of both the dates by no. of milliseconds in a day (1000*60*60*24) Print the final result using document.write().
Not that I'm aware of. But you can always adjust the year:
YourDate="7/11/20";
DateObj=new Date(YourDate.replace(/(\d\d)$/,"20$1"));
alert(DateObj);
This code in action.
Edit: The following code will handle both full and short years:
YourDate="7/11/2020";
DateObj=new Date(YourDate.replace(/\/(\d\d)$/,"/20$1"));
alert(DateObj);
This code in action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With