![]()  | 
  
Chilkat  HOME  Android™  AutoIt  C  C#  C++  Chilkat2-Python  CkPython  Classic ASP  DataFlex  Delphi DLL  Go  Java  Node.js  Objective-C  PHP Extension  Perl  PowerBuilder  PowerShell  PureBasic  Ruby  SQL Server  Swift  Tcl  Unicode C  Unicode C++  VB.NET  VBScript  Visual Basic 6.0  Visual FoxPro  Xojo Plugin
 
      (SQL Server) Extract Timestamp from ULIDSee more ULID/UUID ExamplesExtract the date/time from a ULID.Important: Chilkat's ULID functionality was introduced in v9.5.0.94. 
 -- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @ulid nvarchar(4000) SELECT @ulid = '01GRH14AA82EY9A7S99YYF2QDY' DECLARE @dt int -- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @dt OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Unix timestamps stored in ULIDs should be UTC... DECLARE @bLocal int SELECT @bLocal = 0 -- Set the CkDateTime from the timestamp contained in the ULID DECLARE @success int EXEC sp_OAMethod @dt, 'SetFromUlid', @success OUT, @bLocal, @ulid IF @success = 0 BEGIN PRINT 'ULID was not valid.' EXEC @hr = sp_OADestroy @dt RETURN END -- You can now get the date/time in any desired format. -- For example: EXEC sp_OAMethod @dt, 'GetAsUnixTime', @iTmp0 OUT, @bLocal PRINT 'Unix timestamp = ' + @iTmp0 EXEC sp_OAMethod @dt, 'GetAsRfc822', @sTmp0 OUT, @bLocal PRINT 'RFC822 = ' + @sTmp0 EXEC sp_OAMethod @dt, 'GetAsTimestamp', @sTmp0 OUT, @bLocal PRINT 'Timestamp = ' + @sTmp0 -- Sample output: -- Unix timestamp = 1675608861 -- RFC822 = Sun, 05 Feb 2023 14:54:21 GMT -- Timestamp = 2023-02-05T14:54:21Z EXEC @hr = sp_OADestroy @dt END GO  | 
  ||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.