tags:

views:

64

answers:

4

Hello,

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?

+6  A: 

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

Erik
Make sure to pass $time into the date() function as the second parameter.
keithjgrant
wow, i'm terrible. Fixed taht up, thanks @keithjgrant
Erik
A: 

strtotime + date

troelskn
+1  A: 
$time_string = 'Tue Jan 05 11:08:27 +0000 2010';
$formated_time = date('Y-m-d h:i', strtotime($time_string));
echo $formated_time;
Pierre-Antoine LaFayette
A: 

Agree with Erik, if you want to do it in one line.

Solution

$date = date('Y-m-d H:i:s', strtotime('Tue Jan 05 11:08:27 +0000 2010'));
Rachel