Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Get Certificate Valid To/From Dates

Demonstrates how to get the certificate "valid from" and "valid to" dates.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCert
LOCAL oCkdt
LOCAL oDt

nSuccess := 0

oCert := CreateObject("Chilkat.Cert")

nSuccess := oCert:LoadFromFile("qa_data/certs/testCert.cer")
IF (nSuccess == 0)
    ? oCert:LastErrorText
    oCert:destroy()
    RETURN
ENDIF

//  Get the certificate valid-from date/time
oCkdt := CreateObject("Chilkat.CkDateTime")
oCkdt:SetFromRfc822(oCert:ValidFromStr)

//  Get the local timestamp string.
? "Valid from: " + oCkdt:GetAsTimestamp(1)
//  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.
oDt := CreateObject("Chilkat.DtObj")
oCkdt:ToDtObj(1, oDt)

? Str(oDt:Day) + "/" + Str(oDt:Month) + "/" + Str(oDt:Year) + "  " + Str(oDt:Hour) + ":" + Str(oDt:Minute)

//  Get the certificate valid-to date/time
oCkdt:SetFromRfc822(oCert:ValidToStr)

? "Valid to: " + oCkdt:GetAsTimestamp(1)
//  Valid to: 2020-03-18T18:59:59-05:00new DtObj dt;
oCkdt:ToDtObj(1, oDt)

? Str(oDt:Day) + "/" + Str(oDt:Month) + "/" + Str(oDt:Year) + "  " + Str(oDt:Hour) + ":" + Str(oDt:Minute)

oCert:destroy()
oCkdt:destroy()
oDt:destroy()