View Full Version : SQL Server timestamp

Sep 15th, 2005, 11: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
Sep 16th, 2005, 12:21 AM
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.

Sep 16th, 2005, 12:24 AM
Thanks - GETDATE() worked like a CHARM ;)

Sep 20th, 2005, 12:28 AM
What do I do to get the date to drop the hours, minutes and seconds so it looks like this: dd/mm/yyyy only