RE: [PHP] datetime formatting problem
| From: | Matt Newell | Date: | Fri, 28 May 2004 21:27:31 +0000 |
| Subject: | RE: [PHP] datetime formatting problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-187171@lists.php.net to get a copy of this message | ||
thanks a bunch torsten. it worked like a charm and i'm off to read up
some more on strtotime.
best,
m.
-----Original Message-----
From: Torsten Roehr [mailto:roehr@zilleon.com]
Sent: Friday, May 28, 2004 2:07 PM
To: php-general@lists.php.net
Subject: Re: [PHP] datetime formatting problem
"Daniel Clark" <dclark@nwlink.com> wrote in message
news:59233.65.203.232.102.1085773458.squirrel@webmail.pacifier.com...
> Isn't "date" a reserved word?
date and dateTime are not reserved in MySQL and can be used as column
names.
>
> > hi all -
> >
> > this is probably straight forward, but i'm learning and would
> > appreciate any insight.
> >
> > i'm using the datetime type in mysql and have been able to
> > successsfully pull the data records's date, but it's failing out and
> > giving me the current time [as in what it says on my system's clock]
> >
> > basically i'm just spitting out all the rows to an html table and
> > would like to have the date AND time formatted as is in the
> > date(...) function at the top of the code demo.
> >
> > thanks!
> > matt
> >
> > ///// begin code demo
> >
> >
> > function formatDate($val)
> > {
> > $arr = explode("-", $val);
> > return date("M d, Y g:i A", mktime(0,0,0, $arr[1], $arr[2],
> > $arr[0])); }
Hi Matt,
try this:
function formatDate($val) {
$timestamp = strtotime($val);
return date('M d, Y g:i A', $timestamp); }
Regards, Torsten Roehr
> >
> >
> > // open database connection
> > $connection = mysql_connect($host, $user, $pass) or die ("Unable to
> > connect!");
> >
> > // select database
> > mysql_select_db($db) or die ("Unable to select database!");
> >
> > // generate and execute query
> > $query = "SELECT * FROM outdoor ORDER BY id ASC"; $result =
> > mysql_query($query) or die ("Error in query: $query. " .
> > mysql_error());
> >
> >
> > // if records present
> > if (mysql_num_rows($result) > 0)
> > {
> > // iterate through resultset
> > // print title with links to edit and delete scripts while($row =
> > mysql_fetch_object($result)) { ?> <tr> <td><? echo $row->id;
> > ?></td>
> > <td><? echo $row->name; ?></td> <td><a
> > href="mailto:<? echo
> > $row->email; ?>"><? echo $row->email; ?></a></td>
> > <td><? echo
> > $row->zip ?></td> <td><? echo formatDate($row->date);
> > ?></td> <td><?
> > echo $row->club_member ?></td> <td><? echo $row->driver
> > ?></td>
> > <!-- <td><font size="-1"><? echo $row->active
> > ?></font></td> -->
> >
> > <td><center><a href="edit.php?id=<? echo $row->id;
> > ?>"><img
> > src="notepad.gif" alt="" width="16" height="16"
> > border="0"></a> <a
> > href="delete.php?id=<? echo $row->id; ?>"><img
> > src="trashcan.gif"
> > alt="" width="16" height="16"
> > border="0"></a></center></td> </tr> <?
> > }
> > }
> >
> > --
> > PHP General Mailing List (http://www.php.net/) To unsubscribe,
> > visit: http://www.php.net/unsub.php
> >
> >
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php