View Full Version : SQL Server timestamp

09-15-2005, 10:30 PM
How do you set up a SQL Server database column to insert a timestamp automatically?

I set the Data Type to "timestamp" but it inserts this in every row: <Binary>

If I set to "datetime" I cannot figure out how to have it insert the stamp - it just gives NULL.

I know how to pass the time to through an insert but would rather the database field handle it by default.

Kid Charming
09-15-2005, 11:21 PM
SQL Server's timestamp is not the same as standard SQL's timestamp; it doesn't actually contain a date and time value. You'll need to create a datetime column with a default of GETDATE() or CURRENT_TIMESTAMP. Note that that will only store the creation time; if you need to store modification times also, I think you'll have to do it in your INSERT. I'm not positive on that last point, though.

09-15-2005, 11:24 PM
Thanks - GETDATE() worked like a CHARM ;)

09-19-2005, 11:28 PM
What do I do to get the date to drop the hours, minutes and seconds so it looks like this: dd/mm/yyyy only