quicksnack86
quicksnack86

Reputation: 89

How to separate date and time using php from date time string?

How to convert this string

$parent = "2011-08-04 15:00:01";

to separate it into two strings:

$child1= "2011-08-04";
$child2 = "12:00:01";

And then convert

$child1 to this format 8.4.2011 

and

$child2 to this format 15:00

Upvotes: 5

Views: 22141

Answers (3)

waseem
waseem

Reputation: 11

date('Y-m-d', strtotime( '2015-04-16 15:00:01' ) );

this will give you correct date format followed by mysql i.e 2015-04-16 03:54:17

Upvotes: 1

afuzzyllama
afuzzyllama

Reputation: 6548

$time = new DateTime("2011-08-04 15:00:01");
$date = $time->format('n.j.Y');
$time = $time->format('H:i');

Upvotes: 11

Shef
Shef

Reputation: 45589

$parent = '2011-08-04 15:00:01';

$timestamp = strtotime($parent);

$child1 = date('n.j.Y', $timestamp); // d.m.YYYY
$child2 = date('H:i', $timestamp); // HH:ss

Upvotes: 8

Related Questions