LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Format Specifiers Syntax does not support AM/PM flag

HI,

I do'nt find how we can convert a time string containing an AM/PM flag and a 24h time format is impossible without changing regional setting of my laptop? (first VI snippet)

Also is it impossible (with native function, and not a custom code to treat PM as a 12h adding) to display a string with AM/PM flag on laptop with 24h time system (regional setting)? (second VI snippet)

(the goal is to sort an array of string containing a date and with any time format)

 

=> Wich "Format Specifiers Syntax" we have to use to treat indifferently a 12h with AM/PM or a 24h time format with any option of Windows regional setting.

 

Thanks for your reply.

 

PS : I know the message "scan from string does not recognize AM/PM flag", but the solution to change Windows regional settings isn't a solution, especially because I have to treat the 2 time formats.

Julien
Download All
0 Kudos
Message 1 of 17
(6,229 Views)

Try something like this.  In the "-1" case just pass the timestamp to the output (in case you don't have LV2015). You can change the constant 17:34:34 to 5:34:00 PM.....

 

TIME.png

0 Kudos
Message 2 of 17
(6,184 Views)

Use Match Pattern to look for the AM/PM string.  If that string is found, use the AM/PM format string.  Otherwise use the 24-hour format string.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 17
(6,147 Views)

Thanks Michel, for your ... Smiley Wink time!

 

Your maths could work if we treat the case of 12am correspond to 0 (and 12:01am -> 0:01, and so on...), that is the reason why I'm search a LabVIEW native code solution (or maybe with .NET framework?) that work on a computer indifferently configured with 24h or am/pm time format.

 

As it's say in LabVIEW help "Format Codes for the Time Format String" topic : "You cannot use <%H> (24-hour clock) and <%p> (AM/PM flag) together in the same time format string. If you use <%I> (12-hour clock) instead of <%H>, <%p> operates properly. "

 

It's impossible on a Windows with regional setting on 24h time format to display the AM/PM flag with deal with "manualy code" to concatenate AM/PM string: see the result of your code (plus my "correction" (doesn't work!) on the format string for "date/time string 2")(see VI snippet)

Michel - code results.png

 

So, it's doesn't work on a Windows (Win7 for my case and I know this the same with XP an I think for 😎 with regional setting set on a 24 hours time format.

Julien
0 Kudos
Message 4 of 17
(6,116 Views)

Thanks crossrulz, also for your ... Smiley Wink time!

As I see in you screenshot you have your computer set on a 12 hours with AM/PM, look at timestamp constant on my computer (with 24h format):

Crossrulz - code printscreen.png

Crossrulz - code result.png

And if it doesn't display in LabVIEW (or Windows system), format string doesn't treat AM/PM flag on a 24h Windows time format computer.

Sorry: it doesn't work...

Maybe this a LabVIEW bug or lake of implementation, so maybe I have to deal with NI support...

Julien
0 Kudos
Message 5 of 17
(6,107 Views)

Try connecting "time string 2" control to Match Pattern function, not the contstant you have connected in the picture.

--
Marko H

OptoFidelity - Enabling Smarter Future

Tampere - Espoo - Oulu - Cupertino - Redmond - Zhuhai

0 Kudos
Message 6 of 17
(6,100 Views)

Right 😉 I made a mistake, but it doesn't change anything :

Crossrulz - code printscreen.png

Crossrulz - code result.png

This code can work if we change the regional settings of Windows to know the AM/PM flag (Administrator account is mandatory...), and restart LabVIEW:

regional settings.png

And restarting LabVIEW is mandatory.... this, and an administrator account, are the reasons for saying: this is not a solution.

result ok after regional settings.png

 

Julien
0 Kudos
Message 7 of 17
(6,091 Views)

The only easy solution (not using .NET framework, maybe this is the solution) is to "manually code" addition and substraction to deal with particular case of 12am and 12pm :

 

solution printscreen.png

Julien
0 Kudos
Message 8 of 17
(6,073 Views)

Hello Julien,

 

You are probably right.

 

For your information, if you want to share code with the community instead of attaching a screen capture you may do a code snippet.  This will allow others to reuse your code.  Code snippet is saved as a *.png file (contains probabely meta-data) and one can download it and drag the downloaded file directly in there VI block diagram to execute the code.

 

See http://zone.ni.com/reference/en-XX/help/371361M-01/lvhowto/create_visnippet/

 

Michel

0 Kudos
Message 9 of 17
(6,057 Views)

Hi LabVIEW fans!

No body think that format a time stamp into string with a 24h format and a 12h with am/pm flag with the same Windows regional settings, should work as coded?

On my Windows computer I have a time display with 24h format (so no AM/PM flag!), and I can't have an am/pm flag in my string, event if I specify hour on a 12h format (%I) with am/pm flag (%p) :

Format TimeString bug.png

Format TimeString bug FP.png

 

I can understand that on a time stamp FP control or indicator you cannot display a 12h with AM/PM on computer with 24h (and no amp/pm flag!) time display format. But I understand less that you cannot format a timestamp into the choosen format? Is it a bug or not?

Thanks.

Julien
0 Kudos
Message 10 of 17
(6,022 Views)