Richard
Richard

Reputation: 6116

SQL Database Timestamp

I have a database where people register on a website and their form data then gets inserted into their database. Along with all that information, I want to insert the time of their registration. For example I have an auto-incrementing ID column which I do nothing in my php script for, the sql database automatically increments that with every new entry. In the same way, can I have a time column that I don't have to do anything in the script for, rather the database will just get the current time and put that along with the other inserted information? I'm using phpMyAdmin and I tried adding a column named Time with the type as DATETIME and the default value as the CURRENT_TIMESTAMP but it woulnd't let me add that and said invalid default value for Time.

Upvotes: 0

Views: 422

Answers (3)

mychalvlcek
mychalvlcek

Reputation: 4046

use timestamp column type e.g.

`inserted` timestamp NOT NULL default CURRENT_TIMESTAMP

Upvotes: 1

Marc B
Marc B

Reputation: 360672

Use a timestamp field, which does exactly what you want.

Upvotes: 1

Ryan Brodie
Ryan Brodie

Reputation: 6620

Change the column type to TIMESTAMP.

Upvotes: 2

Related Questions