如何将Windows NT时间从SQL查询请求转换为可读格式? 我正在做用户帐户的广告提取,我想将Windows AD时间戳转换或转换为更好的可读格式。问题是我在进行拉动时无法进行转换。
查询:
SELECT
CASE
WHEN CHARINDEX('@',userPrincipalName) > 7
THEN SUBSTRING(userPrincipalName,1,(CHARINDEX('@',userPrincipalName)) - 1)
ELSE ''
END AS edipi,UPPER(samaccountname) AS samaccountname,givenName AS firstName,sn AS lastName,initials,UPPER(mail) AS email,useraccountControl,telephoneNumber,title,accountExpires
FROM
OPENQUERY
(ADSI,'select
givenName,samaccountName,userPrincipalName,sn,mail,accountExpires
from ''LDAP PATH''
where objectcategory=''person'' and objectclass = ''user'' and name=''*'' '
);
我的查询返回Windows NT时间的accountExpires字段,但我希望它是这样的:
2020-02-09 15:23:36.367
代替此:
132257354163700000
我想出了一个简单的解决方案,一个接一个地进行转换,但是我希望它在下拉时执行CAST,而不必为每个用户都进行
DeclARE @accountExpired BIGINT
SET @accountExpired = 132257354163700000; --This is a random time pulled from a user from the above select statement.
SELECT CAST((@accountExpired / 864000000000.0 - 109207) AS DATETIME);