I want to convert 18 digit string from LDAP AccountExpires to Normal Date Time Format.
129508380000000000 >> May 26 2011
I got the above conversion from using the following link.
I tried to convert by using DateTime.Parse or Convert.ToDateTime. But no success.
Anyone know how to convert it? Thanks very much.
Some info for anyone who came here looking to set the AccountExpires value.
To clear the expiry is nice and easy:
However if you try to directly write back an int64 / long:
You can get a 'COMException was unhandled - Unspecified error'
Instead write back the value as a string data type:
Be aware of the time of day you are setting, for consistancy with ADUC the time should be 00:00.
Instead of .Now or .UtcNow you can use .Today:
Other input like dateTimePicker you can replace the time, Kind as Local for the Domain Controller:
Someone had the "best" way above but when it's set to never expired, the value is zero.
For Ruby
If you View Source on the link you posted you should see a Javascript conversion algorithm that should translate quite nicely to c#
I stumbled across this working on a PowerShell script. I found I can query the
accountexpirationdate
property and no conversion is required.Edited answer
It's the number of ticks since Jan-01-1601 in UTC, according to Reference, which describes the significance of the year 1601. Good background reading.
Original Accepted Answer
It's the number of ticks since Jan-02-1601.