LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help with .NET DateTime.Now.Ticks (or getting nanoseconds since Jan 1, 0001)

Solved!
Go to solution

I have a requirement to send a date in nanoseconds since Jan 1, 0001, which seems to be the standard output of the DateTime.Now.Ticks .NET property.  Since the conversion appears to get a little confusing back in 1752, I was thinking it would be best to just use the .NET feature (which is probably what is being used ont he other end anyway).  But I cannot for the life of me figure out how to do this in LabVIEW.

 

If anyone can provide an example or gude me as to where it is hiding in the .NET list, I would appreciate it.  If you have other suggestion, I am open to those as well.

 

Thanks,

Matthew

0 Kudos
Message 1 of 8
(5,835 Views)

Mathew,

 

I do not have very much experience with .NET, but managed to cobble together the VI which I attach. It returns the current time using the DateTime object.

For some reason I cannot get the Ticks method to work, but this may help you get started.

Message Edited by nrp on 07-29-2009 09:56 AM
Message 2 of 8
(5,814 Views)
Solution
Accepted by topic author Matthew_Kelton

The problem is that the LabVIEW <-> .NET interface automatically converts DateTime.Now to a LabVIEW timestamp datatype, even though it's a .NET DateTime class. This is convenient if you're on the LabVIEW side, but useless if you need to process it further in .NET. Thus, you need to convert it back into a DateTime class.

 

See attached.

Message 3 of 8
(5,796 Views)

Thank you to both for the help.  This is exactly what I needed.  I was of course looking in the wrong place for the class, which didn't help myself.

 

NRP, the Now function doesn't set the value of the object, which is why Ticks didn't work, as the value of the object was still 0.

 

0 Kudos
Message 4 of 8
(5,784 Views)

Wow! I clearly know less about .NET than I thought. I would *never* have guessed to typecast the time to a reference to get the Ticks data!

 

Thanks

0 Kudos
Message 5 of 8
(5,755 Views)

nrp wrote:

Wow! I clearly know less about .NET than I thought. I would *never* have guessed to typecast the time to a reference to get the Ticks data!

 

Thanks


I thought the same when I saw the solution. Boy is that NOT intuitive to do!

 

Rolf Kalbermatter

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 8
(5,742 Views)

rolfk wrote:
I thought the same when I saw the solution. Boy is that NOT intuitive to do!

Unfortunately, that can be said about a LOT of .NET. Smiley Very Happy

 

I still have to resort to the documentation whenever I have to create delegates. 

0 Kudos
Message 7 of 8
(5,730 Views)
I built a LabVIEW VI which doesn't use .NET since my customer didn't want to have to make sure it was installed on all systems.  The attached VI adds an offset to the LabVIEW time.  Based on my testing, I see some error of -2 to +1 ticks, which I am assuming is caused by LSB errors in the conversion.  In my case, it was not important.
0 Kudos
Message 8 of 8
(5,606 Views)