LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan string to Timestamp AM PM flag reversed

Solved!
Go to solution

Hello,

I have a VI that converts a time string to a time stamp.  The AM and PM flags get reversed when I do the conversion.

 

Any ideas on why this occurs?

 

Thanks

 

Dan Shangraw, P.E.


   

0 Kudos
Message 1 of 8
(4,453 Views)

Try to make current control values default before saving so we have something to play with and we know what you are entering

0 Kudos
Message 2 of 8
(4,446 Views)

Thought I did that.

 

Sorry.

 

Here is the VI with values set at default.

 

Thanks

Dan Shangraw, P.E.


   

0 Kudos
Message 3 of 8
(4,443 Views)

Thanks. You probably set the default value for the array element instead of for the array.

 

Yes I see the flip but I am not familiar enough with timestamps trying to decide what, if anything, is the problem.. (see also this discussion for other time curiosities :D) 

0 Kudos
Message 4 of 8
(4,431 Views)
Solution
Accepted by topic author ASTDan

Interestingly, the two elements without the time component alternate time values on each iteration.

First:

time1.PNG

 

Second:

time2.PNG

 

EDIT: Found it here

Don't use %H, which is 24 hour format.  Use %I

Message 5 of 8
(4,420 Views)

Mancho,  That is something extra odd on yours.  I'm looking at it in LV 2016f2, and both of my last two elements show it as 7 am.

 

ASTDan,  Altenbach brought up a good recent thread.  Pay particular attention to my last message in that thread.  https://forums.ni.com/t5/LabVIEW/UTC-0-001-seconds/m-p/3598948#M1008490  where I linked to two older threads, that both seem to apply in your case.

 

1.  When using the %p flag for AM/PM, you should NOT be using the %H flag.  It should be %I  (eye) for a 12 hour clock.  Put in %I, it fixes the first two elements.  (However, it also gives default dates/times on the last two elements)

2.  You have automatic error handling turned off for your VI.  Why?  Turn that back on.  I needed to do that to figure out why the last elements stopped giving data.  It then showed an error 1 because of the invalid scan from string.  And that makes sense because you are asking for scanning a string that has date and time values in it, but those last two only contain date values.

 

The first thread I linked was primarily talking about the results between %y (2 digit year) and %Y (4-digit year) and behavior that changed depending on if the incoming string had 2 digits or 4 digits.  Though we aren't talking about years here, it seems like somewhat the same effects in terms on how strict the function applies the rules for scanning the string.  The second thread is the one that dove into the %I vs. %H for the hour code.

 

Message 6 of 8
(4,397 Views)

RavensFan, it is odd, but I'm not going to concern myself with it, since, as you pointed out, scan from string is producing errors for those, as it should.

0 Kudos
Message 7 of 8
(4,379 Views)

Correction: I do NOT get an error using 24-hour format (%H), but since I reopened the file, I don't get the alternating times.  I really would expect to get the same error on formatting regardless of hour format.Smiley Mad

0 Kudos
Message 8 of 8
(4,359 Views)