# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution
Highlighted

## Re: number of seconds since midnight

Time Stamp.  Front Panel under numeric control

Quotient Remainder.  Block diagram under numeric

To DBL.  Block Diagram under numeric >> conversion

Message 11 of 28
(290 Views)
Highlighted

## Re: number of seconds since midnight

@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)
Message 12 of 28
(285 Views)
Highlighted

## Re: number of seconds since midnight

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

15 hours x 3600 seconds / hour = 54000

???

Message 13 of 28
(281 Views)
Highlighted

## Re: number of seconds since midnight

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

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

## Re: number of seconds since midnight

@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
Message 15 of 28
(274 Views)
Highlighted

## Re: number of seconds since midnight

@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

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 16 of 28
(274 Views)
Highlighted

## Re: number of seconds since midnight

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

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

## Re: number of seconds since midnight

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

Message 18 of 28
(267 Views)
Highlighted

## Re: number of seconds since midnight

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
(249 Views)
Highlighted
Solution
Accepted by topic author psuedonym

## Re: number of seconds since midnight

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

Message 20 of 28
(246 Views)