Best way to input and validate custom datetime in PHP form

This is a twofold question in terms of usability of the foreground and PHP DATE_TIME authentication.

I am working on a site for a client who would like to add a date when he completed the project (therefore, projects can be listed in this order). He will be the only one using the admin interface, so I would like it to be as simple as possible.

I store dates as DATE_TIME in SQLite db.

I would like to require that the client enter at least a year and a month , with the possibility of adding a day, hour, minute, second to DATE_TIME. If they are not installed, they will by default have the smallest number.

I thought that the best way and the easiest way to do this is to make one input form by entering the input (on the left) and making the result (on the right). Using the xxxx / xx / xx / xx / xx / xx format as the format.

2009/08       = 2009-08-01 00:00:01
2009/08/01    = 2009-08-01 00:00:01
2009/08/01/05 = 2009-08-01 05:00:01

(adding one second by default, otherwise it will be the day before)

At first, I tried to crack the input into an array and check each section of the date with a regular expression. it became messy, and I can’t figure out how to check the correct ranges, say [1980-2009] / or / [01-12] / (this does not work as I expected). Also / [(0-9) {2}] / will not work for a month, obviously.

- . . html, , 31 , javascript, , . . , .

, , , ?

+3
1

strtotime() , , , /, //, //: --:

strtotime , , false ( -1 PHP, ). , :

  • stripslashes ( ) strtotime
  • , value === false. ,
  • , yor, date()
+7

Source: https://habr.com/ru/post/1714121/


All Articles