convert date to ticks

R

raghu1

How to convert a given date to its equvalent ticks.:
string d="5/15/2006 12:10:44 PM";

// string 2 date ...
dt=Convert.ToDateTime(d);

// Date 2 ticks ...
dt2ticks=dt.Ticks;
string ticks = Convert.ToString(dt2ticks);


Console.WriteLine("Input date: {0} Ticks: {1} ",d, ticks);

Though there is no error, I get the wrong ticks:
632832918440000000

This ticks number is used to query AD: last logon time (ADSI) and it is
not giving correct results.

I was trying to build a small console apps where in the date in
mm/dd/yyyy format is a command line parameter and the apps prints out
the equvalent ticks ???
 
J

Jon Skeet [C# MVP]

raghu1 said:
How to convert a given date to its equvalent ticks.:
string d="5/15/2006 12:10:44 PM";

// string 2 date ...
dt=Convert.ToDateTime(d);

// Date 2 ticks ...
dt2ticks=dt.Ticks;
string ticks = Convert.ToString(dt2ticks);

Console.WriteLine("Input date: {0} Ticks: {1} ",d, ticks);

Though there is no error, I get the wrong ticks:
632832918440000000

In what way is that "wrong"? From the docs for the property:

<quote>
The value of this property represents the number of 100-nanosecond
intervals that have elapsed since 12:00:00 midnight, January 1, 0001.
</quote>

632832918440000000x100ns = 63,283,291,844s
= 17,578,692.2 hours
= 732,445.507 days
~= 2005.3 years

Looks about right to me.
This ticks number is used to query AD: last logon time (ADSI) and it is
not giving correct results.

Chances are that you don't want the same kind of ticks as the property
is giving you. Do you have docs for the parameter you're passing and
exactly what it should be?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top