November 14th, 2000, 09:02 AM
-
Hi
I'm trying to add the current date to a MySQL db using the following INSERT stmt:
$comment = "INSERT INTO $tableName (sent) VALUES ('CURDATE()')";
I'm trying to put it in a column that is defined as follows:
| sent | date | YES | | NULL
The problem is all dates are stored as 0000-00-00, not 2000-11-15 as I expect...
Can someome tell me whats going on here. It seems I being rather dumb, but don't know why
Cheers
Chris.
November 14th, 2000, 09:13 PM
-
Take out the single quotes around CURDATE(). You're telling mysql to store the actual string, which it doesn't interpret as a date, so you get all zeros.
You can also use NOW()
Have fun...
---John Holmes...
------------------
*************************************************************
* The manual can probably answer 90% of your questions...
*
* PHP Manual. www.php.net/manual
* MySQL Manual: www.mysql.com/documentation/mysql/bychapter
*************************************************************
November 15th, 2000, 03:33 AM
-
John
Many, many thanks John.
Cheers
Chris.
November 21st, 2000, 03:01 PM
-
I like to insert an integer value from the time() function, then later, when I take it out of the database, I can just format it anyway I like it using the date() function. Very nice.
November 21st, 2000, 11:21 PM
-
It's very, very nice if you just use the mysql date and time formats and use the DATE_FORMAT() function in mysql to do your formating...instead of extra PHP code. very, very nice.
You create extra work for yourself by storing unix timestamps in mysql.
---John Holmes...