Page 1 of 1

Store current date to MySQL table via PHP

Posted: Mon Mar 27, 2006 3:54 pm
by dt
Sorry for the novice question...

I have a form and a PHP script that takes the input of that form and inserts a line into an MySQL table. All works fine except I am having trouble getting the current date value added. In the PHP code I have something like the following:
$today=date("Y-m-d");

And I have tried a variet of formats such as:
$today=date("m/d/y");

If I echo the variable $today, it is what I would expect (i.e. 2006-03-26 in the first case, 03/26/2006 in the second).

In my PHP table I have tried having the column be of type date, datetime, and char (I would prefer date or datetime), but regardless I cannot get the value stored in $today inserted in a date (or date-like character) format into the table. If the column is of type date or datetime it allways appears as 0000-00-00, never the actual value from $today. If I change it to type char I get some strange decimal number (as if it is performing the math of month/day/year).

Any help with what I am missing (probably something obvious) would be appreciated.

Thanks,

Daryl

Posted: Mon Mar 27, 2006 4:04 pm
by Gambler
You can simply use NOW() (MySQL function) to insert current date into any row.
insert into tablename (date) values (NOW())
[/quote]

Thanks

Posted: Mon Mar 27, 2006 5:49 pm
by dt
Thanks gambler, I figured I was over complicating the issue...