RE: [PHP] Yes, a newbie and a date question
| From: | Dan Joseph | Date: | Fri, 16 May 2003 17:38:24 +0000 |
| Subject: | RE: [PHP] Yes, a newbie and a date question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147939@lists.php.net to get a copy of this message | ||
Check out the mktime() function on php.net. That should get you where you
want to be.
-Dan Joseph
> -----Original Message-----
> From: Shrader, Patrick [mailto:pshrader@wkep.com]
> Sent: Friday, May 16, 2003 1:39 PM
> To: PHP General
> Subject: [PHP] Yes, a newbie and a date question
>
>
> Greetings, list! I am new to PHP and MySQL, though not to programming (big
> iron machines). I have been stumbling for a while now on a date problem. I
> have a MySQL database setup where I need to display a shipdate to
> the user.
> I need the date and the day of week in separate fields.
>
> I want to convert the MySQL timestamp field to 5/15/2003 and "Friday".
>
> My date value is stored as a MySQL timestamp value, length 14.
>
> The results of the following code is as follows:
>
> Ship Date n/j/Y Day of Week Timestamp Value
> 1/18/2038 Monday 20030103000000
> 1/18/2038 Monday 20030103000000
> 1/18/2038 Monday 20030103000000
> 1/18/2038 Monday 20030123000000
> 1/18/2038 Monday 20030217000000
>
> How can I get the date() function to pick up the 20030103, not
> the 000000?
>
> I appreciate any insights and help you can give me.
>
> Cheers...
> Patrick
>
>
> CREATE TABLE shipdetail (
> sdacct int(8) DEFAULT '0' NOT NULL,
> sdshipd timestamp(14),
> ....
>
> Here is my code (selected):
> $query = "select * 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["sdshipd"];
>
> // convert the timestamp to mm/dd/yy format
> $sdate = date("n/j/Y", $shipdate);
> // convert the timestampt 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>";
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>