Home:ALL Converter>SQL insert unix timestamp with milliseconds

SQL insert unix timestamp with milliseconds

Ask Time:2015-09-11T19:56:19         Author:luisdev

Json Formatter

Can unix timestamps contain the milliseconds value of the time?

If so, using SQL Server 2008 R2:

CREATE TABLE [dbo].[my_table_calls_log]
(
    [id] [bigint] IDENTITY(1,1) NOT NULL,
    [requestdate] [bigint] NULL,
    [partycode] [bigint] NULL,

    CONSTRAINT [PK_my_table_calls_log] 
    PRIMARY KEY CLUSTERED ([id] ASC)
)

The following select gives me the current date and time with milliseconds:

SELECT CONVERT(VARCHAR,SYSDATETIME(),121);

Example:

2015-09-11 13:29:02.8239061

How do I convert that long YYYY-MM-DD HH:MM:SS.MS date/time value into a unix timestamp so that I can insert it using something like:

DECLARE @UnixDate AS bigint;

SET @UnixDate = "the unix timestamp equivalent of SELECT CONVERT(VARCHAR,SYSDATETIME(),121);"

INSERT INTO my_table_calls_log (requestdate,partycode)
VALUES (@UnixDate,123);

Author:luisdev,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32522947/sql-insert-unix-timestamp-with-milliseconds
yy