Hallo can someone explain the behaviour of strtotime function with year in non-standard format.
echo date("d-m-Y",strtotime('02-12-10')) .'<br>'; //10-12-2002
echo date("d-m-Y",strtotime('09.09.10')) .'<br>'; //02-09-2010 --How this is interpreted?
echo date("d-m-Y",strtotime('02-12-2010')) .'<br>'; //02-02-2010
echo date("d-m-Y",strtotime('09.09.2010')) .'<br>'; //09-09-2010
I wanted to convert strings of format dd.mm.yy(09.09.10) to datetime format.
strtotime()can be a bit flaky in such cases. It is built to recognize standard american date formats.If you can use PHP > 5.3, consider using DateCreateFromFormat which has the big advantage of accepting a pre-defined format string to parse the incoming data.
On pre-5.3 platforms,
strptime()seems to offer a second-best alternative. It’s not available on Windows and has some minor issues – be sure to read the manual page before using.