Jump to content

Time Stamp in LabVIEW is off by 300 years...


c_w_k

Recommended Posts

Hello,

One of my many questions is on creating a timestamp in LabVIEW....

I'm getting a value from a C++ DLL that returns the seconds since 01/01/1970 ("epoch"). I'm then trying to use the LabVIEW "SecondsToDate/Time" vi to convert this to a readable time format. When I do this the date is off by 300 years.....is there a trick to doing this? Is the labVIEW "SecondsToDate/Time" vi capable of converting time from 01/01/1970 or does it use a different date to convert from??

I'm wondering if it may be easier to create a timestamp just by using labVIEW instead of trying to convert the epoch variable that is returned by the C++ dll? For example my vi is gathering data constantly from a device, instead of taking the epoch variable from the C++ code I think I could possibly create a labVIEW time stamp each time the vi collects data........my first choice would be to convert the epoch variable that is provided from the C++ DLL.....

so any help on taking a C++ variable and converting it into a timestamp in LabVIEW would be greatly appreciated...

I've attached below, the code that I have so far....

-CK

post-15930-126142934037_thumb.jpg

Link to comment

I'm getting a value from a C++ DLL that returns the seconds since 01/01/1970 ("epoch"). I'm then trying to use the LabVIEW "SecondsToDate/Time" vi to convert this to a readable time format. When I do this the date is off by 300 years.....is there a trick to doing this? Is the labVIEW "SecondsToDate/Time" vi capable of converting time from 01/01/1970 or does it use a different date to convert from??

If you read the help for the LabVIEW Seconds to Date/Time, you'll see that LabVIEW's "epoch" date is 12:00 a.m., Friday, January 1, 1904. You can determine the number of seconds between your epoch date and LabVIEW's, then add that amount before doing the conversion. Also make sure to use a numeric format with enough bits to store your number of seconds, taking LabVIEW's epoch date into account.

Link to comment

1970 epoch = 21600 (hopefully these are right, found them on a website that calculates epoch dates)

1904 epoch = -2082823200

======================

difference of -2082844800

so I added -2082844800 to the variable that is sent in from my C++ DLL......and I now get a year of 2246, which isn't as bad as being off by 300 years....but i've still got a ways to go.....the DLL is getting the value from a device simulator so I wonder if it is sending a bogus number.....

Link to comment

so I added -2082844800 to the variable that is sent in from my C++ DLL......and I now get a year of 2246, which isn't as bad as being off by 300 years....but i've still got a ways to go.....the DLL is getting the value from a device simulator so I wonder if it is sending a bogus number.....

2082844800 is within an hour (+/- for DST). I use 2082848400 for talking with Linux/Solaris systems and that works correctly. Do you know for sure that your dll is returning the correct value?

Link to comment

If the remote device is sending you a value that is the number of seconds since 1/1/1970 00:00:00, then create a timestamp constant on the block diagram, and set the value to 1/1/1970 00:00:00. Use the add primitive to combine the epoch with the DLL seconds.

LabVIEW tip: easy relative timestamp calculations

post-949-12614868642_thumb.png

Edited by Phillip Brooks
  • Like 1
Link to comment

1970 epoch = 21600 (hopefully these are right, found them on a website that calculates epoch dates)

1904 epoch = -2082823200

======================

difference of -2082844800

so I added -2082844800 to the variable that is sent in from my C++ DLL......and I now get a year of 2246, which isn't as bad as being off by 300 years....but i've still got a ways to go.....the DLL is getting the value from a device simulator so I wonder if it is sending a bogus number.....

How big is your number then? As you can see 66 years (1970 - 1904) corresponds roughly to 2*10^9 seconds. From your 300 year difference I would guess you are not getting the number of seconds but rather something else such as the number of ms, since that ominous 1970 date.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.