1

I have a date in this format:

"23/02/2017 6:14:30"

How can I convert it to default MySQL format?

2017-02-23 06:14:30

Here's what I've tried but it didn't work.

$date = "23/02/2017 6:14:30";

$date_new = date( 'Y-m-d H:i:s', strtotime( $date ) );

echo $date_new; // outputs: 1969-12-31 21:00:00
Vinny
  • 597
  • 3
  • 11
  • 26
  • it fails because "Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. If, however, the year is given in a two digit format and the separator is a dash (-, the date string is parsed as y-m-d." http://php.net/manual/en/function.strtotime.php there is no 23rd month –  Feb 23 '17 at 03:24

1 Answers1

0
$newdate = substr($date,6,4) . '-' . substr($date,3,2) . '-' . substr($date,0,2) . substr($date,10);