10-10-2019 02:11 PM
Time Stamp. Front Panel under numeric control
Quotient Remainder. Block diagram under numeric
To DBL. Block Diagram under numeric >> conversion
10-10-2019 02:14 PM - edited 10-10-2019 02:16 PM
@psuedonym wrote:
Sorry.
I mean the solution by crossrulz.
I am not understanding how that solution works because it looks like I have to manually enter today's midnight.
???
His solution works by dividing the current time (Time is stored internally as number of seconds elapsed since the Epoch) by the number of seconds in one day.
The remainder is the number of seconds elapsed since midnight of the current day.
That is as I said BRILLIANT!
10-10-2019 02:16 PM
3:00:00.000 pm ====> 68400 using the VI
15 hours x 3600 seconds / hour = 54000
???
10-10-2019 02:18 PM - edited 10-10-2019 02:23 PM
@psuedonym wrote:
Don't I need to input the current midnight using this method?
Unless I am not understanding this.
No, you do not need to compute the number of seconds as midnight. What my code does is divide the number of seconds since the epoch (Midnight on January 1, 1904, UTC) by the number of seconds in a day. So the Quotient will be the number of days since 1904. The remainder will be the seconds since today started (UTC time).
I just used a Timestamp Control (in the Numeric palette) as an input to prove the algorithm. You can use the Get Date/Time In Seconds to use the current time. Attached is a more complete VI that I would use if I was doing it for myself. I saved it in LabVIEW 8.0.
10-10-2019 02:19 PM
@psuedonym wrote:
3:00:00.000 pm ====> 68400 using the VI
15 hours x 3600 seconds / hour = 54000
???
You are exactly 4 hours off, which I would guess is due to a timezone setting.
10-10-2019 02:20 PM
@crossrulz wrote:
A simple Quotient & Remainder will do the trick...
Wouldn't that be off by 27 seconds as of now?
And would gradually get worse?
Leap seconds being the cause of the error?
Ben
10-10-2019 02:22 PM
@psuedonym wrote:
3:00:00.000 pm ====> 68400 using the VI
15 hours x 3600 seconds / hour = 54000
???
There is a quote out there that goes something like "If you don't hate time zones, you're not a real programmer". The timestamp is based on UTC time. You are apparently in EDT (Eastern Daylight Time). You can somehow pass in the time zone, compute the offset yourself, or just only use UTC. Due to my current work, I just stick with UTC (lots of GPS).
10-10-2019 02:23 PM - edited 10-10-2019 02:24 PM
FYI: Use the function instead of a Control.
The Remainder/Quotiant is found in the Numeric menu.
EDIT: Apparently I am way too slow and missed the whole second page! LOL
10-10-2019 02:30 PM
Thanks all.
I will use the more convoluted way of calculating since I don't have to worry about which time zone is running the VI. I did find https://forums.ni.com/t5/Example-Programs/Convert-a-time-stamp-from-UTC-to-Locale-and-back/ta-p/3505... which discusses converting UTC to local.
10-10-2019 02:33 PM
I love crossrulz's solution, but have to adjust for current timezone. Or just do this.