I'm putting together a simple test database to learn MVC with. I want to add a DateTime field to show when the record was CREATED.
ID = int
Name = Char
DateCreated = (dateTime, DateTime2..?)
I have a feeling that this type of DateTime capture can be done automatically - but that's all I have, a feeling. Can it be done? And if so how?
While we're on the subject: if I wanted to include another field that captured the DateTime of when the record was LAST UPDATED how would I do that.
I'm hoping to not do this manually.
Many thanks
Mike
You need to set the "default value" for the date field to getdate()
. Any records inserted into the table will automatically have the insertion date as their value for this field.
The location of the "default value" property is dependent on the version of SQL Server Express you are running, but it should be visible if you select the date field of your table when editing the table.