Page 1 of 1

DATE_FORMAT

Posted: Mon Jul 05, 2004 5:15 am
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

Posted: Mon Jul 05, 2004 10:11 am
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 :? )

Posted: Thu Jul 08, 2004 6:48 am
by Skittlewidth
well I learned something new today...thanks!