Posted by: R Manimaran | February 23, 2007

Finding No. of ticks Between Two Dates in C#

In Some cases we need to calculate the No.of ticks between two time or dates.In c# we can use this function to find the no of ticks.
Here i calculate the ticks between 1970,1,Jan

DateTime dt70 = new DateTime( 1970, 1, 1, 0, 0, 0, 0 );
long ticks1970 = dt70.Ticks;

To calculate up to current time

int gmt = (int) ((DateTime.UtcNow.Ticks – ticks1970 ) / 10000000L);

or you can convert back:

int gmt = 0x3e482b89; // sample GMT time in seconds since 1970
DateTime yourDateTime = new DateTime( ticks1970 + gmt * 10000000L );


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: