Posted By: Anonymous
I am trying to convert a date from
dd/mm/yyyy => yyyy-mm-dd. I have using the mktime() function and other functions but I cannot seem to make it work. I have managed to
explode the original date using
'/' as the delimiter but I have no success changing the format and swapping the
'/' with a
Any help will be greatly appreciated.
Dates in the
d-m-yformats are disambiguated by looking
at the separator between the various components: if the separator is a
/), then the American
m/d/yis assumed; whereas if the
separator is a dash (
-) or a dot (
.), then the European
format is assumed. Check more here.
Use the default date function.
$var = "20/04/2012"; echo date("Y-m-d", strtotime($var) );
EDIT I just tested it, and somehow, PHP doesn’t work well with dd/mm/yyyy format. Here’s another solution.
$var = '20/04/2012'; $date = str_replace('/', '-', $var); echo date('Y-m-d', strtotime($date));