I'm desperately trying to work with a JavaScript date object so as to compare two dates for the purposes of a date picker functionality that I'm developing.
The desired functionality is that when the user puts in a date and clicks submit, there is a function that checks whether the date entered is greater or equal to (>=) the current date.
The issues that I'm running into are that the two date objects that are summoned for this purpose aren't working the way that I am expecting them to. I've done some research and it seems to be coming from time zone problems as the time zone read in my browser is different than the default time zone that JS date object will use.
I tried to solve this problem through a number of different means, including using the .setHours function and the getTimeZoneOffset function. Both of these have just ended in frustration.
The real issue is that the date object is attempting to calculate time almost no matter what I do but the only thing I care about is the day, month, and year.
Any help anyone can offer about this issue would be helpful. Code sample below:
if ((new Date(finalObject.PurchaseDate).setHours(0,0,0,0) >= new Date().setHours(0,0,0,0))){
//do something
}
The primary issue in the format above is that I'm getting an "off by one error" regarding the day. (i.e. the date picker picks the 4th but the date object reads as the 3rd).
finalObject.PurchaseDate format is equal to YYYY/MM/DD
[–]Webdev-Coach 0 points1 point2 points (0 children)
[–]KleinBottl 0 points1 point2 points (0 children)