LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

number of seconds since midnight

Solved!
Go to solution

Time Stamp.  Front Panel under numeric control

Quotient Remainder.  Block diagram under numeric

To DBL.  Block Diagram under numeric >> conversion

0 Kudos
Message 11 of 28
(243 Views)

@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!

-------------------------------------------------------------------
Unfortunately, most readers of this Forum, including some real Experts, have not mastered the skill of being able to read the code that Posters fail to post. If we cannot see "what you did wrong", we are unable to tell you how to fix it. (Bob Schor 28 August 2018)
0 Kudos
Message 12 of 28
(238 Views)

3:00:00.000 pm ====>  68400  using the VI

 

15 hours x 3600 seconds / hour = 54000

 

???

0 Kudos
Message 13 of 28
(234 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 14 of 28
(233 Views)

@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.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 15 of 28
(227 Views)

@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

0 Kudos
Message 16 of 28
(227 Views)

@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).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 17 of 28
(223 Views)

FYI: Use the function instead of a Control.

image.png

 

The Remainder/Quotiant is found in the Numeric menu.

 

image.png

 

EDIT: Apparently I am way too slow and missed the whole second page! LOL

0 Kudos
Message 18 of 28
(220 Views)

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.

 

 

Message 19 of 28
(202 Views)
Solution
Accepted by topic author psuedonym

I love crossrulz's solution, but have to adjust for current timezone.  Or just do this.

seconds today.png

Message 20 of 28
(199 Views)