Kyle
Kyle

Reputation: 35

Simple PHP date question

I have the following string:

$date = 2011-08-29 14:53:15;

when I do this:

echo date('F j, Y', $date);

I get December 31, 1969 instead of August 29, 2011. How to get the right date?

Upvotes: 1

Views: 122

Answers (3)

Shackrock
Shackrock

Reputation: 4701

<?php
   $date = strtotime($date);
   echo date('F j, Y', $date);
?>

To explain...

The function date() is expecting a unix time-stamp (something like 23498034). the function strtotime() takes a normal looking date that a person would make, and converts it to a timestamp. Then you're good to go.

Upvotes: 2

Korvin Szanto
Korvin Szanto

Reputation: 4511

echo date('f j, Y',strtotime($date));

Upvotes: 2

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324790

Use strtotime on your $date value.

Upvotes: 7

Related Questions