简体   繁体   中英

PHP Format/Validate Date

Say I am assuming a date format of DDMMYYY is being sent to me. However, somebody may send 01022014 , another may send 1022014 , another may send 122014 and yet another the year can be given just as 14 . This last case is not very significant. I am more worried about the day and the month.

How can I validate the date, and accept all of these format, and then reformat it to what I want in PHP?

Short answer is you can't. You have to enforce the formatting rule in the frontend somehow. For example, show the months as a select drop down to remove ambiguity and reduce the possibility of human errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM