PHP DateTime class constructor argument validation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

PHP DateTime class constructor argument validation

Hi SoloLearners ✋ Upon seeing a question about difference of times https://www.sololearn.com/Discuss/2697030/?ref=app I was inspired to try out PHP's date difference function. But then I realized, that PHP DateTime class' constructor was *probably* buggy, in the fact that it allows its string argument (a date/time expression string) to be an invalid date/time expression e.g. February 30th or 31st. Although it doesn't allow the date part to be greater than 31, but still, I find it to be ridiculously funny. My question, do we have to manually validate a date/time expression to the DateTime class constructor, or is there a better way? also is it a bug, or is it my bad in using the class' constructor? Please anyone, an enlightenment? Thank you in advance 🙏 https://code.sololearn.com/wM7H5z16FVWC/?ref=app

15th Feb 2021, 9:25 AM
Ipang
2 Answers
+ 2
https://stackoverflow.com/questions/19271381/correctly-determine-if-date-string-is-a-valid-date-in-that-format/19271434
16th Feb 2021, 7:35 PM
Jaky Ahmed
Jaky Ahmed - avatar
+ 1
Terima kasih bro 🙏
17th Feb 2021, 12:33 AM
Ipang