NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate with timestamps in string format

Hi,

i have the following string as valid timestamp: "22.06.2005 17:47:55,16"
Is there any statement/expression in TestStand available to transform this string into a
valid number of seconds, because i want to calculate the difference between too
values of this type.

Regards,
Sunny
0 Kudos
Message 1 of 3
(3,653 Views)
Sunny -
TestStand does not have any expression functions to do this. You will have to either write a complex expression to attempt to determine the number of seconds, or use a code module to do the conversion.

It appears that your date format can be parsed easily. Here is a starter expression that calculates the seconds since the start of 2005. I have not validated the leap year part but I think that I have accounted for it properly...

'Assume date is stored in Locals.Date like this 22.06.2005 17:47:55,16
'Year = Mid(Locals.Date, 6, 4)
'Month = Mid(Locals.Date, 3, 2)
'Day = Mid(Locals.Date, 0, 2)
'Hour = Mid(Locals.Date, 11, 2)
'Minutes = Mid(Locals.Date, 14, 2)
'Seconds = Mid(Locals.Date, 17, 2) + Mid(Locals.Date, 20, 2)/100

Locals.Seconds =
'Years since 2005 minus 1 day per leap year
((((Val(Mid(Locals.Date, 6, 4)) - 2005) * 365 )
- Round((Val(Mid(Locals.Date, 6, 4)) - 2005)/4))
* 24 * 60 * 60)

'Months minus 1 day if after February in leap year
+ ((({0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}[Val(Mid(Locals.Date, 3, 2))] )
- Val( ( Val(Mid(Locals.Date, 3, 2))>2) && (((Val(Mid(Locals.Date, 6, 4)) - 2005)%4)==3) ))
* 24 * 60 * 60)

'Days
+ ((Val(Mid(Locals.Date, 0, 2))-1) * 24 * 60 * 60)

'Hours
+ (Val(Mid(Locals.Date, 11, 2)) * 60 * 60)

'Minutes
+ (Val(Mid(Locals.Date, 14, 2)) * 60)

' Seconds
+ (Val(Mid(Locals.Date, 17, 2)) + Val(Mid(Locals.Date, 20, 2))/100)
Scott Richardson
0 Kudos
Message 2 of 3
(3,641 Views)
Hi Scott,

thanks for your idea to solve my problem. The way to do this in
TestStand seems to be very complex. I will look for a solution to
solve it by using LabVIEW!

Regards,
Sunny
0 Kudos
Message 3 of 3
(3,633 Views)