PHP convert date from european to US format (dd/mm/yyyy => yyyy-mm-dd)

EU and US manage dates with different formats,
in PHP you can convert the date format from European style to US style using DateTime::createFromFormat
11788381-php-mysql-development

It is the right way to do the job, but surfing on the web I found an alternative way that helps me when I have to prepare a field to store into a MySql database.

The code is simple and self-explanatory, anyway it explodes the source string in substrings containing dd mm and yy then reverses the order of the elements of the array and, last, rebuilds the string using the minus sign as separator.

Gg

You can find the source of this tip at this link

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *