How to convert LDAP timestamp to Unix timestamp

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);

$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


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