Re: display formatted date??
| From: | Kris Dahl | Date: | Mon, 26 Jun 2000 18:45:18 +0000 |
| Subject: | Re: display formatted date?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-3166@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.
I tend to use PHP to format dates upon display, so that I don't need to
convert dates back to another format in order to re-insert the date into the
database.
One thing I do know is that some of the date/time functionality wasn't
around in some of the older versions of PHP (I seem to remember 3.0.8 or so
not having a lot of the formatting stuff) so you need to keep an eye out for
that. Also, you may want to use PHP date formatting stuff as an abstraction
layer between the database. I mean that you may not be able to easily
switch databases if you are using a lot of MySQL functions that don't exist
with, for example PostgreSQL.
-k