1

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?

7
  • why is the first line commented out? Commented Jul 30, 2020 at 18:24
  • Please show example of the startDate value? Commented Jul 30, 2020 at 18:26
  • Could you please give the string you used. It probably is giving you milliseconds. Commented Jul 30, 2020 at 18:29
  • Coming through Vue Data, I have made you a comment line for information purposes. It normally comes as data. Commented Jul 30, 2020 at 18:41
  • @NoahStahl Now edited code line. (Value: 31/07/2020 20:00) Example.. Commented Jul 30, 2020 at 18:43

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello, i not want using other library. Thanks for comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.