Reputation:
I have one String-formatted Datetime.
I want to give an error if a value has been selected in the 12-hour interval after the current date. However, I do not know how to change data.
I used the following line of code.
// this.startDate0 = Input value (string) (Value: 31/07/2020 20:00)
console.log(Date.parse(this.startDate0)); // Maybe NaN maybe 1581099600000
I did not understand how to do it, can you help?
Upvotes: 1
Views: 110
Reputation: 7553
If you're open to using a library, I'd suggest using the date-fns parse function. Supply the expected pattern as a parameter and it will parse the value. You can then use the helper differenceInHours method to compare with 12 hours from present.
Upvotes: 1