LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Regional Settings for Absolute Time Format in Scan from String

Using LV2015 SP1, I'm trying to convert a string to timestamp using Scan From String VI. The input string is like: "01:08PM-25/04/18" and the format string is: "%<%I:%M%p-%d/%m/%y>T". The conversion works just fine on my PC with English settings in Canada, but produces an error (Scan from String (arg1)) on a client's machine in Mexico. Digging deeper, I found this in LabVIEW help about the format specifier:

 

Format Specifier Syntax

%T specifies absolute time. Any information you include with the < and > brackets indicates how you want to format the absolute time. This format, including the punctuation, changes based on the regional settings of the computer.

 

It does not give any further explanation as how it changes. I am explicitly setting the format specifier and the input matches the specifier. Not sure which part is left to the computer's regional settings, and not sure how we can fix it so it works on every system regardless of the regional settings.

 

Any help would be really appreciated.

 

Thanks,

 

Soheyl

 

ScanFromStringFormat.PNG

0 Kudos
Message 1 of 7
(3,455 Views)

Hi Soheyl,

 

how we can fix it so it works on every system regardless of the regional settings.

Two workarounds:

1. Use a better time stamp format like "180425-1308" (yymmdd-HHMM)… 😄

2. Parse the string "manually" with a format like "%d:%d%3s%d/%d/%d" and create your timestamp from the single values…

 

If you need to parse that string you may also prepare/convert it for easier "automatic parsing". You may replace the AMPM part, you may replace the "/" between the date numbers, you may remove the "-" between time and date…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(3,437 Views)

You may try with a format string of %<%X-%x>T. If the input string is the result of a system confirming time format then this should work. If it is however some custom made format variant that only resembles the system format, then you will have to do a lot more work.

Rolf Kalbermatter
My Blog
0 Kudos
Message 3 of 7
(3,424 Views)

1- The string is generated by a 3rd party program, so I cannot change it.

 

2- How can I create timestamp from string bits without using the Scan from String VI and encountering the same problem? Is there a VI for that?

0 Kudos
Message 4 of 7
(3,412 Views)

Well %X inside an absolute time format container (%<>T) is supposed to match the local time format as configured in the Windows time format control panel, while %x is supposed to be the local date format. Did you try what I suggested?

Rolf Kalbermatter
My Blog
0 Kudos
Message 5 of 7
(3,406 Views)

The date is translated to 25/04/1600!! 

0 Kudos
Message 6 of 7
(3,403 Views)

Hi Sohey4,

 

How can I create timestamp from string bits without … encountering the same problem?

The "hard" way:

check.png

I don't care about those subtle annoyances of the AM/PM marker with time (like 12:01AM = 00:01 in 24h format), that would be up to you…

 

One problem always comes from using years with only two digits like in your case: the "standard" behaviour usually expects 4 digits!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 7
(3,380 Views)