0

I want to validate datetime field

<datetime v-validate="'before:2016-05-25|date_format:yyyy-MM-dd|required'" format="YYYY-MM-DD" name="DateTime" width="100px" id="DateTime" :class="['form-control', {'is-invalid': errors.has('DateTime')}]" v-model="DateTime" ></datetime>

This part is working and validating also.

This is only accepting and validation date but i want to enter time also, when i enter yyyy-MM-dd H:i:s it does not validate date time anymore and i want to make this date before:2016-05-25 dynamic it should get the current date time.

Any help is highly appreciated.

1 Answer 1

1

Part of the problem is your date_format pattern string for the time (H:i:s):

  • H is the pattern for hour (not zero-padded)
  • i is the pattern for ISO day of the week
  • s is the pattern for seconds (not zero-padded)

But time is usually shown as HH:mm:ss:

  • HH is the pattern for hour (zero-padded)
  • mm is the pattern for minutes (zero-padded)
  • ss is the pattern for seconds (zero-padded)

Also, the before param must match the date_format pattern string, so if a time pattern were included, the before param would also need to include a time value.

For example, to validate a date before 2016-MAY-25 at 12:30pm:

<datetime v-validate="'before:2016-05-25 12:30:00|date_format:yyyy-MM-dd HH:mm:ss|required'">

demo

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.