DATE_FORMAT

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

DATE_FORMAT

Post by JayBird »

I have a table that that contains lots of dates.

Normallly to format a date when pulling it from MySQL, i would do the following

Code: Select all

SELECT *, DATE_FORMAT(pi_date, '%d-%m-%Y') AS display_date......
...but, in this instance there are about 10 dates to format at once, and producing a query with 10 DATE_FORMAT functions seems a bit excessive.

Is there another way to do it within the query, or would it be better creating a PHP function to format the date after it has been pulled from the DB?

Cheerz

Mark
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

well i always just use the time() function and then format accordingly

for eg (i know you dont need it explaining but here goes

Code: Select all

$time = time();
$format_time = date("j, n, Y", $time);
i used to use the date_format function but had numerous problems with it, including what you descrive as well as ordering problems

if you can get away with it mark, i highly recommend you use the aforementioned method

(you actually got me to start using this method :? )
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

well I learned something new today...thanks!
Post Reply