Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Get Certificate Valid To/From DatesDemonstrates how to get the certificate "valid from" and "valid to" dates.
-- 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 DECLARE @iTmp1 int DECLARE @iTmp2 int DECLARE @iTmp3 int DECLARE @iTmp4 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @cert int -- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @cert, 'LoadFromFile', @success OUT, 'qa_data/certs/testCert.cer' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert RETURN END -- Get the certificate valid-from date/time DECLARE @ckdt int EXEC sp_OAMethod @cert, 'GetValidFromDt', @ckdt OUT -- Get the local timestamp string. EXEC sp_OAMethod @ckdt, 'GetAsTimestamp', @sTmp0 OUT, 1 PRINT 'Valid from: ' + @sTmp0 -- Valid from: 2017-03-17T19:00:00-05:00 -- Now get the date/time as another object where we can get the individual numeric date parts. DECLARE @dt int EXEC sp_OAMethod @ckdt, 'GetDtObj', @dt OUT, 1 EXEC sp_OAGetProperty @dt, 'Day', @iTmp0 OUT EXEC sp_OAGetProperty @dt, 'Month', @iTmp1 OUT EXEC sp_OAGetProperty @dt, 'Year', @iTmp2 OUT EXEC sp_OAGetProperty @dt, 'Hour', @iTmp3 OUT EXEC sp_OAGetProperty @dt, 'Minute', @iTmp4 OUT PRINT @iTmp0 + '/' + @iTmp1 + '/' + @iTmp2 + ' ' + @iTmp3 + ':' + @iTmp4 EXEC @hr = sp_OADestroy @dt EXEC @hr = sp_OADestroy @ckdt -- Get the certificate valid-to date/time EXEC sp_OAMethod @cert, 'GetValidToDt', @ckdt OUT EXEC sp_OAMethod @ckdt, 'GetAsTimestamp', @sTmp0 OUT, 1 PRINT 'Valid to: ' + @sTmp0 -- Valid to: 2020-03-18T18:59:59-05:00 EXEC sp_OAMethod @ckdt, 'GetDtObj', @dt OUT, 1 EXEC sp_OAGetProperty @dt, 'Day', @iTmp0 OUT EXEC sp_OAGetProperty @dt, 'Month', @iTmp1 OUT EXEC sp_OAGetProperty @dt, 'Year', @iTmp2 OUT EXEC sp_OAGetProperty @dt, 'Hour', @iTmp3 OUT EXEC sp_OAGetProperty @dt, 'Minute', @iTmp4 OUT PRINT @iTmp0 + '/' + @iTmp1 + '/' + @iTmp2 + ' ' + @iTmp3 + ':' + @iTmp4 EXEC @hr = sp_OADestroy @dt EXEC @hr = sp_OADestroy @ckdt EXEC @hr = sp_OADestroy @cert END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.