Skip to content

Form checking: Craft allows to enter invalid dates #10078

Answered by brandonkelly
JuliaSang asked this question in Ideas
Discussion options

You must be logged in to vote

Thanks for the report!

  • In a date field enter "31/31/2021"
  • Click Save
  • Craft will store a different date "7/31/2023"

This is awkward but actually working as expected. Assuming your user account’s formatting locale is set to “English (United Kingdom)”, Craft knows the submitted date will be in the format d/m/Y e. And if you were to run the following PHP code:

DateTime::createFromFormat('!d/m/Y e', '31/31/2021 UTC')

That would return a DateTime object with a value of 2023-07-31 00:00:00.000000. The way it sees it, the 13th month of 2021 is January 2022; the 14th month of 2021 is February 2022; etc… and the 31st month of 2021 is July 2023. Does that make sense?

* In a date field enter "ab…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants