Michael Fesser wrote:
.oO(Kenneth Downs)
Andy Hassall wrote:
Either fetch a UNIX timestamp from MySQL (I think it's TO_UNIXTIME or
similar), or get MySQL to format it for you using DATE_FORMAT in the SQL
statement.
or $cdate=date("r",strtotime($cdate));
strtotime is cool.
DATE_FORMAT() is cooler.
Micha
Yeah, but its a DB function.
<opinion category="mild rant">
My own tastes run to having PHP as the middleman do all of the formatting.
In the one direction PHP takes user input and turns it into formatted SQL
writes (insert, update, etc) and in the other direction it takes db-native
data from a SELECT and formats it for human consumption.
If you have a data dictionary, you write two simple functions that take care
of all of this for you:
function SQL_FORMAT($user_value,$type) // makes SQL-acceptable strings...
function HTML_FORMAT($sql_value,$type) // makes user-readable strings...
Where $type is pulled from the dd. If different sites and/or users want
different date display styles, you can have HTML_FORMAT read a preferences
file.
While there is nothing "wrong" with DATE_FORMAT(), it would muddy this clean
placement of responsibilities.
</opinion>
but of course to each his own.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)