Re: display formatted date??

From: Date: Mon, 26 Jun 2000 18:57:34 +0000
Subject: Re: display formatted date??
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3171@lists.php.net to get a copy of this message
> > There may be a MySQL function that can format the date; I don't > > know. > > There is... The DATE_FORMAT() function. > > for example: > > "SELECT DATE_FORMAT(CURRENT_DATE(), "%b %D, %Y") as todaysdate"; > > Would return "Jun 26th 2000" > > I am not sure what is more efficient, however. I think PHP gives you more > flexibility that the SQL query as far as how you can format dates. I > imagine that the performance difference is fairly negligible, so I guess > either way is okay for formatting dates. The performance should be very similar if you aren't doing calculations (e.g. SELECT ... WHERE FormatedDateField = '26/2000' is basically evil). However, the problems I've found are that it's more work to perform date calculations and it does require you to change the SQL queries to modify the date output. Currently I'm using SELECT UNIX_TIMESTAMP(datefield) in my queries and using date() to format the result. This works nicely in the context of user configurable displays where the date string is configurable by the user (e.g. MM/DD/YYYY, DD/MM/YYYY, Month Day, YYYY etc.).

« previous php.general (#3171) next »