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

I want to have a range of time that the user selects, could be anything. Let’s say 5AM to 5PM. If the current time is within this time range, output True.

 

Does something like this exist in LabView already? Or am I gonna have to come up with my own solution 🙂

0 Kudos
Message 1 of 19
(1,773 Views)

In Range & Coerce does accept timestamps.  So you can use that to do the comparison 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 2 of 19
(1,763 Views)

"In range and coerce" accepts timestamps, but the dates must agree too, of course.

You could covert the timestamp to a date/time record (using "seconds to date/time") and unbundle hours (and lower) and compare.

 

 

Message 3 of 19
(1,760 Views)

EDIT: nevermind disregard this


0 Kudos
Message 4 of 19
(1,734 Views)

@David99999 wrote:
What do you mean by "date/time record"?

The output cluster of "seconds to date/time".

Message 5 of 19
(1,732 Views)

You might just want to format all times in %H:%M:%S format and do a string comparison.

 

altenbach_0-1657652861155.png

 

Message 6 of 19
(1,728 Views)

Ok I'm very interested in that solution, I need to stare at it a little longer though.

 

Problem is, I don't actually have any timestamps. When I receive the time data from the user, it's just a separate string for the hour, a separate string for the minute, and another for the AM/PM, which is all in a cluster.

 

Sooooo....I may have made my life harder than it needs to be by doing that, instead of using timestamps. I don't want to rewrite the code, so I was thinking I could create a timestamp myself with my own values from the user. So far this is the solution I have been messing with, but it's not working out how I thought. It also may be entirely more difficult than it needs to be. Which is why I'm staring at the code you just posted.

 

timestamp issue.png

0 Kudos
Message 7 of 19
(1,722 Views)

All you probably need is my code here.

 

Convert the user times to the correct format (converting am/pm to 24h) and create the 6 digit string HHMMSS. Format the current time the same way.

Note that "format date/time" does NOT require an timestamp input (as claimed in your diagram comment). Unwired, it defaults to the current time.

Message 8 of 19
(1,714 Views)

I think I also need to explain that I want to convert those 12 hour times to 24 hour times, and it seems that I need to have a timestamp to do so with any of these functions.

 

I haven't looked but maybe there's a manual mathmatical way of converting a 12 hour time to 24 hour time

0 Kudos
Message 9 of 19
(1,711 Views)

OK, your VI makes very little sense. The user cannot enter values into diagram constants, so these need to be controls. I am also not sure why you think you need a greedy loop for any of this, just burning through CPU as fast as the computer allows.

 

Please provide exact specifications:

 

What does the user provide and in what format? can we assume it is always well-formed?

.You are using the "to timestamp" completely wrong. It expects a DBL scalar.

Message 10 of 19
(1,706 Views)