Asked  9 Months ago    Answers:  2   Viewed   38 times

I've a date formatted like "Tue Jan 05 11:08:27 +0000 2010" and I want to convert it's format to "yyyy-mm-dd 00:00" in PHP.

How can I do that?



convert it to a PHP date object with strtotime() then output it with date()


Some more detail; try:

$time = strtotime('Tue Jan 05 11:08:27 +0000 2010');
echo date("Y-m-d h:i", $time);

Y = 4 digit year m = 2 digit month (with leading 0) d = 2 digit month (with leading 0)

h = 12 hour time (leading 0) i = minutes (with leading 0) for all the formatting options

Wednesday, March 31, 2021
answered 9 Months ago

You need to convert it to something you can use for further formatting. strtotime() is a good start, which yields a unix timestamp. You can format that one using strftime() then.

strftime("%d-%b-%G", strtotime($ts));
Wednesday, March 31, 2021
answered 9 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :