Re: adding the date to a database
| From: | Christopher Ostmo | Date: | Wed, 18 Jul 2001 20:17:21 +0000 |
| Subject: | Re: adding the date to a database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-58519@lists.php.net to get a copy of this message | ||
Brad Wright pressed the little lettered thingies in this order...
> Hi,
> I have a database with a 'date' field. What is the syntax for using the
> (mysql) function 'getdate()', to insert the date into the DB table.
> the syntax I'm currently using is:
> $query = "Insert INTO visits (visName, date)
> values ('$name', getdate()) " ;
> $result = mysql_query($query, $db);
>
If you're using MySQL 3.23 (or newer) and the field is one of the date,
time or datetime types, use NOW()
For example:
$query = "Insert INTO visits (visName, date)
values ('$name', NOW()) " ;
This returns a "YYYY-MM-DD HH:MM:SS" string that MySQL will
automatically convert to any of the date/time field types.
Christopher Ostmo
a.k.a. tech@AppIdeas.com
AppIdeas.com
Innovative Application Ideas
Meeting cutting edge dynamic
web site needs since the
dawn of Internet time (1995)
For a good time,
http://www.AppIdeas.com/