07-12-2022 12:11 PM
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 🙂
Solved! Go to Solution.
07-12-2022 12:32 PM
In Range & Coerce does accept timestamps. So you can use that to do the comparison for you.
07-12-2022 12:33 PM
"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.
07-12-2022 01:58 PM - edited 07-12-2022 02:00 PM
EDIT: nevermind disregard this
07-12-2022 02:00 PM
@David99999 wrote:
What do you mean by "date/time record"?
The output cluster of "seconds to date/time".
07-12-2022 02:08 PM - edited 07-12-2022 02:08 PM
You might just want to format all times in %H:%M:%S format and do a string comparison.
07-12-2022 02:22 PM
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.
07-12-2022 02:27 PM - edited 07-12-2022 02:31 PM
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.
07-12-2022 02:29 PM
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
07-12-2022 02:37 PM - edited 07-12-2022 02:47 PM
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.