Jump to content

[SOLVED] Formatting a date pulled out of mysql in php


Mr Chris

Recommended Posts

Hello,

 

I have a date set in a database in a field called published like so:

 

2009-01-23 08:00:00

 

and I query the database to get the site out in a set format like so:

 

Friday, 23rd January, 2009

 

$SQL = "SELECT *, DATE_FORMAT(published, '%W, %D %M, %Y') AS formatted_date from blah"
$result = mysql_query($SQL) OR die(mysql_error()); 
$formatted_date = $row['formatted_date'];

 

However, I also want to get the date out in the published field in following format as well:

 

yyyy/mm/dd

 

How can I do this please?

oh sorry I thought you were trying to figure out how to do it lol. wouldn't this work:

 

$SQL = "SELECT *, DATE_FORMAT(published, '%W, %D %M, %Y') AS formatted_date, DATE_FORMAT(published, '%Y/%m/%d') AS another_formatted_date from blah"
$result = mysql_query($SQL) OR die(mysql_error()); 
$formatted_date = $row['formatted_date'];
$another_formatted_date = $row['another_formatted_date'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.