Oliver Kucharzewski
Oliver Kucharzewski

Reputation: 2645

Change date to string with month and day

How can I change the current date format which is: YY/MM/DD to something like Oct 8th 2013.

This will be pulled straight from database.

Was not sure what to google in-order to find this. Thanks.

Upvotes: 0

Views: 100

Answers (3)

Striver
Striver

Reputation: 1

Sql get current time:

select DATE_FORMAT(NOW(),'%b %D %Y') FROM table;

or date format the exist time:

SELECT DATE_FORMAT(time, '%b %D %Y) FROM table;

Upvotes: 0

Jon
Jon

Reputation: 4736

As I linked in comments, use DateTime::createFromFormat

And the resulting code would be something like:

$date = "13/10/08";
$tmp = DateTime::createFromFormat("y/m/d", $date);
echo $tmp->format("M jS Y");

Output:

Oct 8th 2013

PHPFiddle

Upvotes: 1

Sverri M. Olsen
Sverri M. Olsen

Reputation: 13283

Use the DateTime class:

$time = DateTime::createFromFormat('y/m/d', '13/10/13');
if ( ! $time) {
    die('Date is invalid!');
}
echo $time->format('M jS Y');

Upvotes: 1

Related Questions