Manipulating time strings in Processbook VBA

Discussion created by AlistairFrith on Aug 18, 2009
Latest reply on Mar 24, 2010 by andreas

We want to be able to convert the timestamp strings provided to the Trend TimeRangeChange event into a system time, so we can compare it. The reason we are doing this is so we can show the display's 'end time' at the top of the display and have it indicate whether the display is showing current data or historical. Essentially, we expect the code to look something like this:


Private Sub Logo_Trend_TimeRangeChange(ByVal StartTime As String, ByVal EndTime As String)
dim et as Date
    dim diffSecs as integer

    et = PIDateToSystemDate(EndTime)      ' <-- ** Essentially, I want to know what function to use here **
    diffSecs = DateDiff("s", EndTime, now())

    if diffSecs > 30 then
    'viewing historic time
        TimeStamp_Text.BackgroundColor = 3844043
    TimeStamp_Text.Contents = ("Historic: " & Format(et, "dd/MM/yyyy HH:mm:ss"))
    else if diffSecs < -30 then
    'viewing future time (probably no data but at least they will know why!)
        TimeStamp_Text.BackgroundColor = 3844043
    TimeStamp_Text.Contents = ("Future: " & Format(et, "dd/MM/yyyy HH:mm:ss"))
        'viewing current time
    TimeStamp_Text.BackgroundColor = -1
        TimeStamp_Text.Contents = ("Current: " & Format(et, "dd/MM/yyyy HH:mm:ss"))
    End If
End Sub


What is the correct function to use to convert a PI time string into the Date format? Also, are we doing anything stupid here?


--- Alistair