I have different DateTime formats and need to convert them to a standardized format.
Is there any build in PHP method which accepts different formats and returning them as a DateTime object or something else easy to format? I searched php.net and also this forum but can’t find anything.
Just want to save time before I start coding something which probably already exists.
my formats to catch:
d.m.Y
d/m/Y
d-m-Y
m.d.Y
m/d/Y
m-d-Y
Y.d.m
Y/d/m
Y-d-m
Y.m.d
Y/m/d
Y-m-d
If there is no PHP method I will write my own class or if someone has something handy to share… 🙂
Thanks!
You can use
DateTime::createFromFormatand your formats in a loop and check if valid object has been created