Reputation:
I have this two DateTime values:2018-08-19T16:00:00Z
and 1534694400
. For the first value i need to remove the T16:00:00Z
from the date, for the second value, I need to convert it in a normal date. How I can do this using the DateTime
class of php?
Upvotes: 3
Views: 8284
Reputation: 1435
<?php
//1st
$date=date_create("2018-08-19T16:00:00Z");
echo date_format($date,"Y-m-d");
//2nd
$date=date_create();
date_timestamp_set($date,1534694400);
echo date_format($date,"Y-m-d");
?>
Upvotes: 0
Reputation: 1844
For the first date:
$dt = new \DateTime('2018-08-19T16:00:00Z');
echo $dt->format('Y-m-d');
For timestamp:
$dt = new \DateTime();
$dt->setTimestamp(1534694400);
echo $dt->format('Y-m-d');
Upvotes: 5