Re: Retrieving formatted date in select query
On Fri, 04 Jan 2008 20:24:53 -0600, seastl <<nospam@nospam.com>>
wrote:
>
>Hello,
>
>I am a novice (very novice) webmaster, and am trying to retrieve the
>most recent record from a database to display on a homepage. It all
>works well enough with one exception, which I am sure is just my
>overlooking something - I cannot change the date format. When I change
>the field "DTE" to a date_format in the query as below, my date
>results are blank. Looking at the code below, can someone please
>suggest what I might be doing incorrectly? Any is greatly
>appreciated -
>
>****
>mysql_connect("localhost", "username", "password") or
>die(mysql_error());
>mysql_select_db("stjojone_primary") or die(mysql_error());
>$data = mysql_query("SELECT
>LTRGCL_DTE,date_format(DTE,'%W,%M,%D,%Y'),BLTN_FI LE FROM
>bulletin_store ORDER BY DTE DESC LIMIT 0,1") or die(mysql_error());
>Print "<div align=center><table class=\"SJTableInfo\">";
>Print "<tr><td align=center><h5>Date</h5></td><td
>align=center><h5>Liturgical Date</h5></td></tr>";
>while($info = mysql_fetch_array( $data ))
>{
>Print "<tr>";
>Print "<td class=\"SJTdInfo\" align=\"center\">".$info['DTE'] .
>"</td><td class=\"SJTdInfo\" align=\"left\"><a
>href=/bulletin_files/".$info['BLTN_FILE'] ." title=\"Click to view or
>download the file\" target=\"_blank\">".$info['LTRGCL_DTE']
>."</a></td>";
>}
>Print "</table></div></br></br>";
>****
Ok, I changed to "date_format(DTE,'%W,%M %D,%Y') as 'DTE',", and seems
to work perfectly now. Then I find that it sorts on the literal date,
not the actual date value now! Is there an easy enough fix for that,
or should one just sort on the ID autonumber column?
|