How to convert a date to this format in PHP?


Can anyone tell me what kind of date is this format?


I have in the database a field of type timestamp or date. How to convert the value of it to this format using PHP?

asked by anonymous 22.04.2015 / 16:55

1 answer


You can get a date in this format, from a record of your MySQL database, like this:

echo date("Y-m-d\TH:m:sP", strtotime($db_date));

Where the variable $db_date is the field you are fetching from your database (regardless of type date or timestamp ), and the output is exactly that you put in your question.

In the PHP documentation for date() you find all these formats that I I used the first parameter. In the second parameter, I just converted your date to Unix timestamp via strtotime() .

As well as the rray quoted here , a more simplified way is to use the c parameter, which already returns a date in the format ISO 8601 :

echo date("c", strtotime($db_date));
22.04.2015 / 18:35