Sample code for 30+ languages & platforms
SQL Server

Get Current Date/Time as Timestamp (YYYY-MM-DDThh:mm:ssTZD)

Demonstrates how to get the current system date/time in YYYY-MM-DDThh:mm:ssTZD format.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @success int
    SELECT @success = 0

    DECLARE @dt int
    EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dt OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @dt, 'SetFromCurrentSystemTime', @success OUT

    -- Get a UTC time.
    DECLARE @bLocal int
    SELECT @bLocal = 0
    DECLARE @timestamp nvarchar(4000)
    EXEC sp_OAMethod @dt, 'GetAsTimestamp', @timestamp OUT, @bLocal

    PRINT 'Current UTC Time: ' + @timestamp

    -- Get a local time.
    SELECT @bLocal = 1
    EXEC sp_OAMethod @dt, 'GetAsTimestamp', @timestamp OUT, @bLocal

    PRINT 'Current Local Time: ' + @timestamp

    -- Sample output:
    -- 
    -- Current UTC Time: 2022-03-01T00:48:58Z
    -- Current Local Time: 2022-02-28T18:48:58-06:00

    EXEC @hr = sp_OADestroy @dt


END
GO