sql server - Is there a way to set my default as the number of seconds since 1970? -
in tables setting current date/time as:
[modifieddate] datetime default (getdate()) not null,
but there way set number of seconds since 1970. unix epoch (or unix time or posix time or unix timestamp) number of seconds have elapsed since january 1, 1970
i realize need have field integer not sure how set default value?
though suggest it's better store datetime2
value or datetime
, can use alex k's suggestion:
declare @t table ( unixtime int default(datediff(second, '1970-01-01 00:00', getdate())), createdate datetime default(getdate()) )
test:
insert @t default values select * @t
result:
unixtime createdate ----------- ----------------------- 1468930170 2016-07-19 12:09:30.380
another option, damien_the_unbeliever suggested, use computed column:
declare @t table ( createdate datetime default(getdate()), unixtime datediff(second, '1970-01-01 00:00',createdate) )
Comments
Post a Comment