views:

117

answers:

1

In active directory there are a bunch of INT64 fields (like lastlogintimestamp, accountexpires, etc)

How do I convert these to datetime values in C#?

+1  A: 

http://securitythroughabsurdity.com/2005/12/active-directory-and.html

What that says, is the correct function is DateTime.FromFileTime, which returns a DateTime object, which is exactly what you need.

Erich
This seems to work.
Christopher
For the record, so does this:DateTime root = new DateTime(1601, 1, 1);DateTime utc = root.AddTicks(timestamp);DateTime local = utc.ToLocalTime();return local;
Christopher
Where timestamp is the INT64 value from AD.Also note that a Int64 value of 9223372036854775807 is the equivelent of null/no value.
Christopher
Good catch on the null/no value. That other solution is mentioned in the link I posted.
Erich