-3

I have a php string from db it is 20/11/2017 I want to convert it milliseconds. It's my code to doing that.

$the_date = "20/11/2017";
$mill_sec_date = strtotime($the_date);
var_dump($mill_sec_date);

But it does not print any thing rather than

bool(false);

What is the problem and how can i solve it ????

LF00
  • 27,015
  • 29
  • 156
  • 295
Kousher Alam
  • 1,005
  • 1
  • 15
  • 30

5 Answers5

3

When using slashes to separate parts of the date, PHP recognizes the format as MM/DD/YYYY. Which makes your date invalid because there is no 20th month. If you want to use the format where day and month is swapped, you need to use hyphens, like DD-MM-YYYY.

Nick Coons
  • 3,682
  • 1
  • 19
  • 21
1
$time = strtotime('10/16/2003');

$newformat = date('Y-m-d',$time);
print_r($newformat);
Ritesh Khatri
  • 1,253
  • 13
  • 29
0

Use DateTime class to call function createFromFormat

    $date = date_create_from_format('d/M/Y:H:i:s', $string);
$date->getTimestamp();
Blesson Christy
  • 380
  • 3
  • 13
0

Most likely you got the date format wrong, see here for a list of supported date and time formats:

This section describes all the different formats that the strtotime(), DateTime and date_create() parser understands.

Marco
  • 7,007
  • 2
  • 19
  • 49
0

You string is not accept by the strtotime, you can use createFromFormat set set the with the format type of the time string like below, you can also check the live demo. And you also can refer to this answer

var_dump(DateTime::createFromFormat('d/m/Y', "20/11/2017"));
LF00
  • 27,015
  • 29
  • 156
  • 295