Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to separate date and time in php?

my date format is like : Wednesday, 22 Apr, 2015, 12:39 PM

How i separate date and time like Below ?

> Date :- April 22 2015

> Time :- 12:39 PM

like image 315
Mahesh Cheliya Avatar asked Dec 15 '22 15:12

Mahesh Cheliya


1 Answers

First remove the commas and use strtotime:

$dt = 'Wednesday, 22 Apr 2015, 12:39 PM';
$dt = strtotime(str_replace(',', '', $dt));
$d = date('F d Y',$dt);
$t = date('h:i A',$dt);
echo $d,'<br/>',$t;

Output:

April 22 2015
12:39 PM
like image 66
n-dru Avatar answered Dec 22 '22 01:12

n-dru