Data-Link UTC Date

Discussion created by matthew.rivett on Dec 31, 2013
Latest reply on Jan 2, 2014 by ee.ashley

There doesn't appear to be any way to return UTC dates in data link.  I asked tech support and they said it was so.  Instead you must convert local date to UTC date.  They provided me with some sample  code to get back the UTCSeconds using PITimeServer and I think modified it to get back a date object.


To OSIsoft:  Please add this feature to data-link!


I'm not that great with date math.  Can anyone spot any issues in this code or is there a better way to accomplish this?

Option Explicit

Public Function ConvertLocalDatetoUTCDate(ByVal vdatExcelDate As Date) As Date
    On Error GoTo Err:
    ' only run if a date is set
    If vdatExcelDate Then
        ' Variables
        Dim pit As New PITimeServer.PITime

        ' Get the Local Date
        pit.LocalDate = vdatExcelDate
        ' convert UTC seconds into days and add the beginning of UTC time (1/1/1970) in days
        ConvertLocalDatetoUTCDate = (pit.UTCSeconds / 60 / 60 / 24) + DateSerial(1970, 1, 1)
    End If
    Exit Function
    MsgBox vdatExcelDate & vbCrLf & Err.Description, vbCritical, "Error"
    Exit Function
End Function