When I retrieve the LDAP attribute \"pwdLastSet\" of an Active Directory using PHP I get a value like 1.29265206716E+17. I know that this value represents the date \"Tue Aug
Rather than ask the same question for another language.
Python 3:
from datetime import datetime, timedelta
def ldap2datetime(ts: float):
return datetime(1601, 1, 1) + timedelta(seconds=ts/10000000)
print(ldap2datetime(132255350424395239).isoformat())
# 2020-02-07T07:44:02.439524
@etranger - correction: should be timestamp from 1601 instead of 1600. Refer to offical microsoft website: http://msdn.microsoft.com/en-us/library/ms675243%28v=vs.85%29.aspx
There's this page suggesting that it is "100-nanosecond units passed since 1.1.1601 00:00:00", this might be helpful.
EDIT: 1600 »» 1601
$dateLargeInt= "1.29265206716E+17"; // nano seconds since jan 1st 1601
$secsAfterADEpoch = $dateLargeInt / (10000000); // seconds since jan 1st 1601
$ADToUnixConvertor=((1970-1601) * 365.242190) * 86400; // unix epoch - AD epoch * number of tropical days * seconds in a day
$unixTsLastLogon=intval($secsAfterADEpoch-$ADToUnixConvertor); // unix Timestamp version of AD timestamp
$lastlogon=date("d-m-Y", $unixTsLastLogon); // formatted date
See http://php.net/manual/en/ref.ldap.php for details
Please see here.
Actually it boils down to converting the FILETIME
timestamp into a UNIX timestamp:
$fileTime = "130435290000000000";
$winSecs = (int)($fileTime / 10000000); // divide by 10 000 000 to get seconds
$unixTimestamp = ($winSecs - 11644473600); // 1.1.1600 -> 1.1.1970 difference in seconds
echo date(DateTime::RFC822, $unixTimestamp);