I want to convert date from, for example, 1441065600 to YYYYMMDD format. How do I do that?
$temp = date("Y-m-d",1441065600);
$rel_date = date_format( $temp, "YYYYMMDD");
The code above gives an error:
date_format()expects parameter 1 to beDateTimeInterface
Simply write:
<?php
echo date('Ymd', 1441065600);
Otherwise, using a DateTime instance:
<?php
echo (new DateTime())->setTimestamp(1441065600)->format('Ymd');
Note: the setTimestamp() method do not takes a string as parameter! Otherwise, you may want to do so:
<?php
$english = '1441065600';
$timestamp = strtotime($english);
$date = new DateTime($timestamp);
echo $date->format('Ymd'); // 20161214
strtotime() - Parse about any English textual datetime description into a Unix timestamp
DateTime - Representation of date and time
Note: I created a new DateTime instance from the UNIX timestamp, English textual representation may lead to an error.
I recommend you to read the DateTime::format() method documentation along with the date() function documentation to learn more about date formats.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With