she hates me
she hates me

Reputation: 1272

Date formatting in PHP

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?

Upvotes: 1

Views: 294

Answers (4)

Rachel
Rachel

Reputation: 103397

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'));

Upvotes: 0

Erik
Erik

Reputation: 20712

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

Upvotes: 6

Pierre-Antoine LaFayette
Pierre-Antoine LaFayette

Reputation: 24402

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

Upvotes: 1

troelskn
troelskn

Reputation: 117447

strtotime + date

Upvotes: 0

Related Questions