LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calculate time from seconds, day of year, and year

Solved!
Go to solution

I've got a data file where they saved three columns, seconds since midnight, day of year, and year.  I'm trying to create a LabVIEW timestamp from these three numbers.  From seconds since midnight, I can create sec, minutes, and hours.  If I feed these into a time cluster with Day of Year and Year, the output timestamp is 0.  Doesn't work.  Although it has a Day of Year input element, apparently the Date/Time to Seconds function requires day of month and month to work.

 

The only obvious solution I can imagine at this point is to calculate month and day from day of year, which would involve a month lookup table and a leap year check.

 

Any clever solutions I'm missing?

DaveT

-------------------------------------------------------------
David Thomson Original Code Consulting
www.originalcode.com
National Instruments Alliance Program Member
Certified LabVIEW Architect
Certified Embedded Systems Developer
-------------------------------------------------------------
There are 10 kinds of people: those who understand binary, and those who don't.
0 Kudos
Message 1 of 7
(6,393 Views)

The day of week and day of year can be 0 and it will still work.  But the month and day of month are required.  I guess you would have to look up the month and day from day of year with a leap year check.

 

22218i4AAE1E1089238192

- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 7
(6,384 Views)
Solution
Accepted by topic author Dave_Thomson

Dave,

 

I found a Julian to Georgian date here.

Message 3 of 7
(6,383 Views)

Thanks, Dennis!  I did do a search, but didn't find that.  I was hoping there was an easy trick like that.

 

Cheers,

   DaveT

-------------------------------------------------------------
David Thomson Original Code Consulting
www.originalcode.com
National Instruments Alliance Program Member
Certified LabVIEW Architect
Certified Embedded Systems Developer
-------------------------------------------------------------
There are 10 kinds of people: those who understand binary, and those who don't.
0 Kudos
Message 4 of 7
(6,374 Views)

I have another way, the DBL conversion VI converts time to a "numeric value" that started counting since the year 1901.  Now you can do some math in a seperate VI to determin how many "numeric values" is 1 year, 1 day, 1 second.  Then do your math to add up all "numeric values" and then convert your DBL to timestamp again.

0 Kudos
Message 5 of 7
(5,664 Views)

@Mattjk wrote:

I have another way, the DBL conversion VI converts time to a "numeric value" that started counting since the year 1901.  Now you can do some math in a seperate VI to determin how many "numeric values" is 1 year, 1 day, 1 second.  Then do your math to add up all "numeric values" and then convert your DBL to timestamp again.


This can get a bit complicated, for example make sure you take care of leap years and such.

0 Kudos
Message 6 of 7
(5,649 Views)

You don't need to worry about a leap year doing it this way.

 

Example:

 

Seconds since midnight: say 60

Day of year: say 222 (60seconds x 60 minutes x 24 hours) X 222= 19180800

Year: say 2014 (Jan. 1st 2014 at exactly 12:00am) (using code) = 3471397200

Each year after = 31536000

 

So just add all the numbers together and use the number to timestamp VI in the timing pallet to convert back to a date.

There is a little bit of work with the year because you can't assume that

 

Year 1900 to 2014 is 114 years which is

114 X 31536000

 

First calcualte an offset value from December 31st 1903 at 7pm to any year that starts with Jan.1st at 12am.

Then add Years after (multiplied by 31536000)

 

0 Kudos
Message 7 of 7
(5,625 Views)