Skip to main content
May 23, 2012
Answered

Timestamp in database for new row

  • May 23, 2012
  • 1 reply
  • 1936 views

I have a timestamp field in my db.
In my mysql program I clicked on the box that says "On Updated Current_Timestamp" which works fine for updating rows in the database and adds the time.
Now I want it to add the time for NEW rows, so in the default box I put now();  but I get an sql error. I am doing it in the database to lessen the load on coldfusion but maybe something like this is better in my cfquery insert into sql?:

<cfqueryparam cfsqltype="cf_sql_timestamp" value="#now()#" />

What do you think I should do? Thanks

This topic has been closed for replies.
Correct answer

It it is truly a timestamp field, there should be no need for a default value... no?


Thanka for all the input I played around a lot with it and I made it work, this is what I did to the timestamp mysql field:

Field length 0.

Decimals 0

Allow null NO

Checkbox for On Update Current_Timestamp selected

Default value CURRENT_TIMESTAMP

It now works fine adding/updating the date for both a new and an exisiting record automatically

Thanks for all the help about dates

1 reply

Inspiring
May 24, 2012

What is the code you are running and what is the error?

May 24, 2012

Hi Dan

The field UPDATED is a timestamp field, it has length 0 because it doesn't let me change it, decimals 0 and allow null.

The Default value I put in the mysql program for the field is: now();

It has the checkbox for On Update Current_Timestamp selected.

I get this error: 1067 'Invalid default value for value updated'

Inspiring
May 24, 2012

I did a google search on "mysql now" and found this page.  http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

I noticed one synonym for now is current_timestamp().  I'd try that with a 0 in the brackets.