LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Are there any functions for detecting if time is within a certain time range?

Solved!
Go to solution

Here's one possibility. It will even do the AM/PM conversion for you.

(If you want, you can leave out the ":" in the format. would make no difference)

 

altenbach_0-1657655300564.png

 

Message 11 of 19
(875 Views)

That what was an example of the flow of logic lol. It's not the actual code I'm using

0 Kudos
Message 12 of 19
(874 Views)

Alrightyyyyyyy I think I'm just gonna use this that I whipped up real quick. Probably not the best, but it'll do. Like I said, I don't have any timestamps to begin with, just strings.

 

This is just to get military time values, then I can use range

 

timestamp issue.png

0 Kudos
Message 13 of 19
(864 Views)

Hi David,

 

why don't you concat your input strings into one timestamp like string and use ScanFromString to parse your time?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 14 of 19
(859 Views)

No, that's still way too convoluted and overly complicated. What if the user enter "am" instead of "AM"? (hint: it would be considered PM!) What if the user enters 55 AM? What if he enter 5 XM?

 

The two pseudo-numeric fields should be numeric with correct input range limits and the AM/PM could be an enum or ring.

 

Did you even look at my earlier suggestion?

Message 15 of 19
(850 Views)

Yes I did, and it appeared as though your solution needed the timestamp data type, which I don't have unless I make one myself.

 

Also, again, these code snippets I'm posting are just examples for how the solution could work. In my actual code, all the hours, minutes, and AM/PM's are enums.

0 Kudos
Message 16 of 19
(847 Views)
Solution
Accepted by topic author David99999

Some fun with Scan From String and Format Into String can do the 12 to 24 hour conversion for you.


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 17 of 19
(840 Views)

That's awesome, thank you!

0 Kudos
Message 18 of 19
(818 Views)

@crossrulz wrote:

Some fun with Scan From String and Format Into String can do the 12 to 24 hour conversion for you.

 


The problem is still that the inputs are strings and thus cannot be easily validated for correctness. Users can type the combined works of Shakespeare in there and the result would be garbage. 😄

 

As I said, I would use a combination of numeric and ring inputs, where the input range is correctly defined in the control(1..12, 0..59, AM=0, PM=12).

 

Here's how that could look like. (I added some optional code to validate the conversion. Of course I have not tested every possible input, so test for yourself 🙂 ).

 

altenbach_0-1657728120936.png

 

 

Message 19 of 19
(810 Views)