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?

 Answers

66

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

EDIT

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)

http://php.net/manual/en/function.date.php for all the formatting options

Wednesday, March 31, 2021
 
alioygur
answered 9 Months ago
43

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
 
Freddie
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 :
 
Share