You can represent an exact date and time in PHP using the built-in DateTime object.
Creating one is simple, just pass it a string in the format YYYY-MM-DD HH:MM:SS.
The problem is that sometimes you want to go from a DateTime object back to a string.
In this post, we'll learn how to convert a DateTime object to a string in PHP.
How to convert a DateTime object to a string
To start, let's create our own DateTime object.
PHP
$date = newDateTime('2020-01-01 00:00:00');
The easiest way to convert this back to a readable string is to call the format method on it and pass it the format in which you want to get the string in.