RE: [PHP-DB] Insert Date
| From: | John W. Holmes | Date: | Mon, 17 Mar 2003 00:29:40 +0000 |
| Subject: | RE: [PHP-DB] Insert Date | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26410@lists.php.net to get a copy of this message | ||
> How would I do the insert statement in php using a date() or now()
> function?
$today = date("Ymd");
$query = "INSERT INTO tblDate (fldDate) VALUES ($today)";
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/
> -----Original Message-----
> From: John W. Holmes [mailto:holmes072000@charter.net]
> Sent: Saturday, March 15, 2003 4:13 PM
> To: 'Jeremi Bergman'; php-db@lists.php.net
> Subject: RE: [PHP-DB] Insert Date
>
> > I'm having problem inserting the date into my mysql database. What
> type
> > of field should my date field be?
> > How do I insert that into a database, the current date for example?
> > "INSERT INTO tblDate (fldDate) VALUES (" . Date() . ")";
>
> You should use a DATE column, maybe?? Or a timestamp, depending on
what
> you want to do.
>
> The query you'd use is:
>
> INSERT INTO tblDate (fldDate) VALUES (NOW())
>
> where NOW() is a MySQL function, not a PHP one. MySQL date formats are
> YYYYMMDD (as an integer) or YYYY-MM-DD (as a string).
>
> Adapt to your needs.