From date with time to date without time in PHP [duplicate]
Asked Answered
K

3

7

I have to convert this string date 2016-09-26 00:00:00.000 to the yyyy-mm-dd format without other characters.

Can you help me, please?

Kata answered 4/10, 2016 at 10:58 Comment(1)
Simplest solution is: $date = preg_replace("/\s{1}\d{2}:\d{2}\:\d{2}/",'',$datetime);Luigi
H
12

You can just use the DateTime class along with the format() method:

$d = new DateTime('2016-09-26 00:00:00.000');
echo $d->format('Y-m-d');
Hummocky answered 4/10, 2016 at 11:0 Comment(0)
G
7

Try this:

$datetime = '2016-09-26 00:00:00.000';

$date = date('Y-m-d', strtotime('2016-09-26 00:00:00.000'));

you will get the only date part in 'yyyy-mm-dd' format.

Gitlow answered 4/10, 2016 at 11:0 Comment(0)
Q
0
$test = strtotime('2016-09-26 00:00:00.000');
$test1 = date('Y-m-d h:i', $test);
$array1 = explode(' ', $var);
$date_temp = $array1[0];
Quodlibet answered 4/10, 2016 at 11:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.