Forum Moderators: open

Message Too Old, No Replies

MySQL and NOW() function

         

tonynoriega

4:45 pm on Jun 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a dbase that stores the date an entry was made with a NOW() function.

I just went in to modify some records and the entry date was changed to when i just modified them.

is there a way to store that value and never have it change if the record is modified?

barns101

8:32 pm on Jun 11, 2007 (gmt 0)

10+ Year Member



It may depend on the datatype of the column. What is it currently set as?

phranque

11:05 pm on Jun 11, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the first TIMESTAMP column will automatically update to NOW() whenever an insert or update (that actually changes a column value) occurs.
if you need to control the value of that column, you must either change it to another type (DATETIME, for example) or explicitly (re)set the date/time value for each update.

coopster

4:17 am on Jun 14, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



... but things changed at MySQL >= 4.1.2


With a DEFAULT CURRENT_TIMESTAMP clause and no ON UPDATE clause, the column has the current timestamp for its default value but is not automatically updated.

[dev.mysql.com...]

... and prior to 4.1.2 ...


The first TIMESTAMP column in table row automatically is updated to the current timestamp when the value of any other column in the row is changed, unless the TIMESTAMP column explicitly is assigned a value other than NULL.

[dev.mysql.com...]

Yes, a big change and one to note across your applications if you are still migrating from earlier servers. Not one of my favorite upgrades in years past ;)