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 17 2010 14:11:11 GMT+0200".
How can I convert this value to a Unix timestamp in PHP? Thanks for any hints!
The current timezone in LDAP is 0. If you want to increase or decrease the timezone, you need to follow the formula 60 seconds multiply 60 minutes multiplied by X hours (60 * 60 * X) = Y will get the number of seconds.
The timestamp is the number of 100-nanosecond intervals (1 nanosecond = one billionth of a second) since Jan 1, 1601 UTC. The current LDAP/Win32 FILETIME is 133050816050000000.
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);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With