yiisoft / validator

Yii validator library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
110 stars 36 forks source link

Date and datetime string validator #602

Closed samdark closed 5 months ago

samdark commented 1 year ago

DateRule validates a string value that represents a date. DateTimeRule validates a string value that represents date and time.

Options

format, see DateTime::createFromFormat()

For Date default could be 'Y-m-d', for DateTime it could be Y-m-d H:i:s.

Implementation

Use \DateTime::createFromFormat() then \DateTime::getLastErrors() or regex + validating if date and time are valid.

samdark commented 1 year ago
Gerych1984 commented 8 months ago

I wrote a similar one for my needs (need to fix namespaces). It may be useful with a little tweaking DateTime.zip