I have the following timeformat:15/08/2011 12:32:23
day/month/year hour:minute:sec and I want to convert to the following format: Y-m-d H:i:s
I tried with date('Y-m-d H:i:s', strtotime($time))
but it not works. It swaps the month and the day when it's converting from string to datenum.
strtotime
understands both American (mm/dd/YYYY
) and European (dd-mm-YYYY or dd.mm.YYYY
) formats. You are using slashes to separate day, month and year, and that's why your date is interpreted as American. To solve that, replace the slashes with dashes.