- Instant help with your Php coding problems

Convert timestamp to DateTime in PHP

Question:
How to convert timestamp to DateTime in PHP?
Answer:
$date = new DateTime();
$date->setTimestamp($timestamp);

echo $date->format('Y-m-d');
Description:

To convert a Unix timestamp to a valid PHP date you can use the DateTime class. First, create a simple DateTime object, then set its value using the setTimestamp method. After that, you can get your date in any format using the format method.

Share "How to convert timestamp to DateTime in PHP?"