(SQL Server) DateTime - Get as Unix Time String
Demonstrates the GetAsUnixTimeStr method.
Note: This example is only valid in Chilkat v9.5.0.65 or later.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @dateTime int
-- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dateTime OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @dateTime, 'SetFromCurrentSystemTime', @success OUT
-- (in seconds since the epoch: 00:00:00 UTC on 1 January 1970)
DECLARE @bLocal int
SELECT @bLocal = 1
EXEC sp_OAMethod @dateTime, 'GetAsUnixTimeStr', @sTmp0 OUT, @bLocal
PRINT 'Unix time: ' + @sTmp0
-- Sample output for test run on 2-Dec-2016:
-- Unix time: 1480661608
EXEC @hr = sp_OADestroy @dateTime
END
GO
|