Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

datetime

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
like image 285
quicksnack86 Avatar asked Aug 04 '11 13:08

quicksnack86


2 Answers

$time = new DateTime("2011-08-04 15:00:01");
$date = $time->format('n.j.Y');
$time = $time->format('H:i');
like image 83
afuzzyllama Avatar answered Oct 25 '22 04:10

afuzzyllama


$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
like image 29
Shef Avatar answered Oct 25 '22 06:10

Shef