Adding Time to Date (ticks)

barx

Well-Known Member
Licensed User
Longtime User
Hi

I am using the Date Dialog and Time Dialog to allow the user to set the date/time respectively.

I then wish to store these as a single ticks value like that returned by DateTime.now.

If the Time is set to 9:00am the ticks value is '-62167446000000'
id the date is set to 12 may 2012 the ticks value is '1336348800000'

thanks
 

specci48

Well-Known Member
Licensed User
Longtime User
The ticks start counting (value = 0) at 01/01/1970 at 00:00.
The TimeDialog returns the time-ticks according to the date 00/00/0000, so you're getting a negative value.

To add both values from Time- and DateDialg (which returns the ticks at 00:00) you have additionally to add the (negative) ticks value for 00/00/0000 00:00, which is -62167478400000.

So in your sample:

-62167446000000 1336348800000 + 62167478400000= 1336381200000


specci48
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…