RE: [PHP] Yes, a newbie and a date question

From: Date: Fri, 16 May 2003 20:08:27 +0000
Subject: RE: [PHP] Yes, a newbie and a date question
Groups: php.general 
Request: Send a blank email to php-general+get-147972@lists.php.net to get a copy of this message
Jason and All, Thanks so much for your help. This was exactly what I needed to get this fixed. For the archives ('cause I'm sure others will find this helpful, too), the final code change is as follows: <?php ... // UNIX_TIMESTAMP does not equal MySQL timestamp. Convert date timestamp as follows, // I added a TS to indicate this is a timestamp value. $query = "select *, UNIX_TIMESTAMP(sdshipd) as sdshipdTS from shipdetail where (sdacct = $account and sdshipd > 20030101)"; $queryresult = mysql_query($query, $data) or die (mysql_error()); // list records read in a table print "<table width='555' border='1' cellspacing='2' cellpadding='0'>"; print "<tr>"; print "<th>Ship Date n/j/Y</th>"; print "<th>Day of Week</th>"; print "<th>Timestamp Value</th>"; print "</tr>"; // process each row while($row_hdr = mysql_fetch_assoc($queryresult)) { $shipdate = $row_hdr["sdshipdTS"]; // convert the timestamp to mm/dd/yy format $sdate = date("n/j/Y", $shipdate); // convert the timestamp to day of week $sdayofweek = date("l", $shipdate); print "<tr>"; print "<td>$sdate</td>"; print "<td>$sdayofweek</td>"; print "<td>$shipdate</td>"; print "</tr>"; } print "</table>"; ... ?> Thanks for all the help! Patrick -----Original Message----- From: Jason Wong [mailto:php-general@gremlins.biz] On Saturday 17 May 2003 02:58, Shrader, Patrick wrote: > How can I use the "SELECT * from xyz" statement and still use the > UNIX_TIMESTAMP() command? Will I have to describe each field > separately? If you only want to change your SELECT statement then you need to select each field explicitly: SELECT UNIX_TIMESTAMP(name_of_date_field) as name_of_date_field, field_a, field_b FROM ... Otherwise use: SELECT *, UNIX_TIMESTAMP(name_of_date_field) as new_name_of_date_field FROM ...

« previous php.general (#147972) next »