Re: Re: datetime update
| From: | Jonathan Haddad | Date: | Thu, 10 Jun 2004 20:12:44 +0000 |
| Subject: | Re: Re: datetime update | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-34730@lists.php.net to get a copy of this message | ||
roehr@zilleon.com wrote:
JonHi all, i have a datetime field in a mysql database and it's defined with a default of '0000-00-00 00:00:00:' now, when i add a record to the database, i want to fill that field with >the date and current time. can anyone point me ?Via PHP: $dateTime = date('Y-m-d H:i:s'); mysql_query("INSERT INTO table SET dateTime = '$dateTime'"); Via MySQL: mysql_query("INSERT INTO table SET dateTime = NOW()"); Take a look here for other useful MySQL date and time functions: http://dev.mysql.com/doc/mysql/en/Date_and_time_functions.html Hope it helps. Regards, Torsten Roehr Yeah, if you are looking for something that automatically sets itself you can use the timestamp type instead. with date or date time you must explicitly use now. remember though, with timestamp, if you update the row the timestamp will automatically update to the current time.