0

I have a string 31/05/2017

And I want to convert it to MYSQL format, 2017-05-31 00:00:00.
What I have done is.

$dateString = '31/05/2017';
$timestamp = strtotime($dateString);
$date = date("Y-m-d H:i:s", $timestamp);

But strtotime is returning false.

zx485
  • 28,498
  • 28
  • 50
  • 59
Abdul Ghaffar
  • 228
  • 3
  • 14

2 Answers2

2

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.

<?php
$dateString = str_replace("/", "-", '31/05/2017');
$timestamp = strtotime($dateString);
var_dump(strtotime($dateString));
echo $date = date("Y-m-d H:i:s", $timestamp);
?>

check below links

http://php.net/manual/en/function.strtotime.php

strtotime returning false date

Community
  • 1
  • 1
msk
  • 481
  • 2
  • 12
0

Please try Following,

$dateString = '31/05/2017';
$timestamp = strtotime(str_replace('/', '-', $dateString )); 
$date = date("Y-m-d H:i:s", $timestamp);

Thanks.

Ramesh
  • 47
  • 5