10-20-2015 08:18 AM - edited 10-20-2015 08:31 AM
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.
10-20-2015 11:18 AM
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.....
10-20-2015 05:46 PM - edited 10-20-2015 05:47 PM
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.
10-21-2015 03:11 AM - edited 10-21-2015 03:12 AM
Thanks Michel, for your ... 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)
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.
10-21-2015 03:22 AM
Thanks crossrulz, also for your ... 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):
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...
10-21-2015 03:58 AM
Try connecting "time string 2" control to Match Pattern function, not the contstant you have connected in the picture.
10-21-2015 04:23 AM - edited 10-21-2015 04:39 AM
Right 😉 I made a mistake, but it doesn't change anything :
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:
And restarting LabVIEW is mandatory.... this, and an administrator account, are the reasons for saying: this is not a solution.
10-21-2015 05:20 AM
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 :
10-21-2015 07:05 AM
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
10-22-2015 03:57 AM
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) :
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.