COnverting Filetime format

  • Thread starter Thread starter Ryan Stewart
  • Start date Start date
R

Ryan Stewart

Is tehre an easy calculation i can use to convert the integer active
directory stores the setpwdlast value in? I believe it is in filetime
format....
 
Are you looking to do this in a script or just a simple way to see the values?

If the former, I will see if I can dig it up, I posted how to do that a year or
so ago in one of these newsgroups. It isn't exactly what I would call simple but
it is doable.

If the later you can use several tools to do that.

1. Would be repadmin with the /showtime option.
2. If you are querying AD I have a command line tool called adfind that will do
the LDAP query for you and you can tell it to convert the values to string times...

I.E.

[Thu 05/20/2004 21:07:35.66]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 127293019455190496


1 Objects returned

[Thu 05/20/2004 21:07:39.36]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset -tdc

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 05/17/2004-17:12:25


1 Objects returned

[Thu 05/20/2004 21:07:42.13]
F:\DEV\cpp\CPAU>


You can get adfind from the free win32 tools page of www.joeware.net. If you
just need a tool to do the conversion I have one of those laying around as well
that I could publish to the joeware site.

joe
 
Ah here, I found one of the previous posts... It gets you to ctime format which
you can use various tools to convert to a string, I have a perl script below to
do it.

joe


I have been asked multiple times for this info in newsgroups and emails
to my joeware email and again at work yesterday so I wrote this up.
Thought I would share with the group here in case anyone cares.

---

First off the 64 bit Integer Time Values (Called Integer8) represents
the number of 100 nanosecond intervals between the time stamp and
January 1, 1601. Don't ask me why, this is just what it is, I am not
even going to attempt to explain it other than I wasn't around prior to
1969 so what happened with computers in 1601 is far outside my personal
scope of really caring. In fact I am not sure anything even existed then
because I didn't, it is up for debate.

1. Remove last 7 characters - Usually this will be all zeros but it may
be actual digits if you care to get down to 100 nanosecond accuracy, you
can figure it out.

2. Subtract off 11644473600

You are now at a value that is the number of seconds since since January
1, 1970. Again I will not explain even though I was around then. I still
wasn't at the point that I worried about time stamps on computers, I was
still flabbergasted that man had walked on the moon 6 short months
previously...

This value was targeted because there are functions out there that use
that format for time already and you can leverage them to convert to a
friendly time/date stamp such as ctime or localtime or gmtime.

So how to do this in perl??

Here is a quick perl script:

___t64.pl___
$t64=shift;
$t64=~s/(.+).{7,7}/\1/;
$t64-=11644473600;
($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat,
$isdst)=localtime($t64); $mon++; $year+=1900;
print "$mon/$mday/$year - $hour:$min:$sec DST - $isdst\n";


When you run it it will produce something like:

C:\Temp>t64 127069827243689315
9/2/2003 - 9:25:24 DST - 1


Use as you wish.

For other cool methods to play with those time fields in Perl check out
Robbie Allen's upcoming book - Active Directory Cookbook. :o)


joe





List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive: http://www.mail-archive.com/[email protected]/





--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net


Are you looking to do this in a script or just a simple way to see the
values?

If the former, I will see if I can dig it up, I posted how to do that a
year or so ago in one of these newsgroups. It isn't exactly what I would
call simple but it is doable.

If the later you can use several tools to do that.

1. Would be repadmin with the /showtime option.
2. If you are querying AD I have a command line tool called adfind that
will do the LDAP query for you and you can tell it to convert the values
to string times...

I.E.

[Thu 05/20/2004 21:07:35.66]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 127293019455190496


1 Objects returned

[Thu 05/20/2004 21:07:39.36]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset -tdc

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 05/17/2004-17:12:25


1 Objects returned

[Thu 05/20/2004 21:07:42.13]
F:\DEV\cpp\CPAU>


You can get adfind from the free win32 tools page of www.joeware.net. If
you just need a tool to do the conversion I have one of those laying
around as well that I could publish to the joeware site.

joe




--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net



Ryan said:
Is tehre an easy calculation i can use to convert the integer active
directory stores the setpwdlast value in? I believe it is in filetime
format....
 
Thanks! Exactly what i was looking for!
Ah here, I found one of the previous posts... It gets you to ctime
format which you can use various tools to convert to a string, I have a
perl script below to do it.

joe


I have been asked multiple times for this info in newsgroups and emails
to my joeware email and again at work yesterday so I wrote this up.
Thought I would share with the group here in case anyone cares.

---

First off the 64 bit Integer Time Values (Called Integer8) represents
the number of 100 nanosecond intervals between the time stamp and
January 1, 1601. Don't ask me why, this is just what it is, I am not
even going to attempt to explain it other than I wasn't around prior to
1969 so what happened with computers in 1601 is far outside my personal
scope of really caring. In fact I am not sure anything even existed then
because I didn't, it is up for debate.

1. Remove last 7 characters - Usually this will be all zeros but it may
be actual digits if you care to get down to 100 nanosecond accuracy, you
can figure it out.

2. Subtract off 11644473600

You are now at a value that is the number of seconds since since January
1, 1970. Again I will not explain even though I was around then. I still
wasn't at the point that I worried about time stamps on computers, I was
still flabbergasted that man had walked on the moon 6 short months
previously...

This value was targeted because there are functions out there that use
that format for time already and you can leverage them to convert to a
friendly time/date stamp such as ctime or localtime or gmtime.

So how to do this in perl??

Here is a quick perl script:

___t64.pl___
$t64=shift;
$t64=~s/(.+).{7,7}/\1/;
$t64-=11644473600;
($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat,
$isdst)=localtime($t64); $mon++; $year+=1900;
print "$mon/$mday/$year - $hour:$min:$sec DST - $isdst\n";


When you run it it will produce something like:

C:\Temp>t64 127069827243689315
9/2/2003 - 9:25:24 DST - 1


Use as you wish.

For other cool methods to play with those time fields in Perl check out
Robbie Allen's upcoming book - Active Directory Cookbook. :o)


joe





List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive: http://www.mail-archive.com/[email protected]/





--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net


Are you looking to do this in a script or just a simple way to see the
values?

If the former, I will see if I can dig it up, I posted how to do that
a year or so ago in one of these newsgroups. It isn't exactly what I
would call simple but it is doable.

If the later you can use several tools to do that.

1. Would be repadmin with the /showtime option.
2. If you are querying AD I have a command line tool called adfind
that will do the LDAP query for you and you can tell it to convert the
values to string times...

I.E.

[Thu 05/20/2004 21:07:35.66]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 127293019455190496


1 Objects returned

[Thu 05/20/2004 21:07:39.36]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset -tdc

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 05/17/2004-17:12:25


1 Objects returned

[Thu 05/20/2004 21:07:42.13]
F:\DEV\cpp\CPAU>


You can get adfind from the free win32 tools page of www.joeware.net.
If you just need a tool to do the conversion I have one of those
laying around as well that I could publish to the joeware site.

joe




--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net



Ryan said:
Is tehre an easy calculation i can use to convert the integer active
directory stores the setpwdlast value in? I believe it is in filetime
format....
 
No problem, just keep in mind, ctime will break in 2038...

:o)



--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net



Ryan said:
Thanks! Exactly what i was looking for!
Ah here, I found one of the previous posts... It gets you to ctime
format which you can use various tools to convert to a string, I have
a perl script below to do it.

joe


I have been asked multiple times for this info in newsgroups and emails
to my joeware email and again at work yesterday so I wrote this up.
Thought I would share with the group here in case anyone cares.

---

First off the 64 bit Integer Time Values (Called Integer8) represents
the number of 100 nanosecond intervals between the time stamp and
January 1, 1601. Don't ask me why, this is just what it is, I am not
even going to attempt to explain it other than I wasn't around prior to
1969 so what happened with computers in 1601 is far outside my personal
scope of really caring. In fact I am not sure anything even existed then
because I didn't, it is up for debate.

1. Remove last 7 characters - Usually this will be all zeros but it may
be actual digits if you care to get down to 100 nanosecond accuracy, you
can figure it out.

2. Subtract off 11644473600

You are now at a value that is the number of seconds since since January
1, 1970. Again I will not explain even though I was around then. I still
wasn't at the point that I worried about time stamps on computers, I was
still flabbergasted that man had walked on the moon 6 short months
previously...

This value was targeted because there are functions out there that use
that format for time already and you can leverage them to convert to a
friendly time/date stamp such as ctime or localtime or gmtime.

So how to do this in perl??

Here is a quick perl script:

___t64.pl___
$t64=shift;
$t64=~s/(.+).{7,7}/\1/;
$t64-=11644473600;
($sec, $min, $hour, $mday, $mon, $year, $wday, $ydat,
$isdst)=localtime($t64); $mon++; $year+=1900;
print "$mon/$mday/$year - $hour:$min:$sec DST - $isdst\n";


When you run it it will produce something like:

C:\Temp>t64 127069827243689315
9/2/2003 - 9:25:24 DST - 1


Use as you wish.

For other cool methods to play with those time fields in Perl check out
Robbie Allen's upcoming book - Active Directory Cookbook. :o)


joe





List info : http://www.activedir.org/mail_list.htm
List FAQ : http://www.activedir.org/list_faq.htm
List archive: http://www.mail-archive.com/[email protected]/





--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net


Are you looking to do this in a script or just a simple way to see
the values?

If the former, I will see if I can dig it up, I posted how to do that
a year or so ago in one of these newsgroups. It isn't exactly what I
would call simple but it is doable.

If the later you can use several tools to do that.

1. Would be repadmin with the /showtime option.
2. If you are querying AD I have a command line tool called adfind
that will do the LDAP query for you and you can tell it to convert
the values to string times...

I.E.

[Thu 05/20/2004 21:07:35.66]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 127293019455190496


1 Objects returned

[Thu 05/20/2004 21:07:39.36]
F:\DEV\cpp\CPAU>adfind -default -b -f name=joeuser pwdlastset -tdc

AdFind V01.15.00cpp Joe Richards ([email protected]) April 2004

Using server: 2k3dc01.joe.com
Base DN: DC=joe,DC=com

dn:CN=joeuser,CN=Users,DC=joe,DC=com
pwdLastSet: 05/17/2004-17:12:25


1 Objects returned

[Thu 05/20/2004 21:07:42.13]
F:\DEV\cpp\CPAU>


You can get adfind from the free win32 tools page of www.joeware.net.
If you just need a tool to do the conversion I have one of those
laying around as well that I could publish to the joeware site.

joe




--
Joe Richards Microsoft MVP Windows Server Directory Services
www.joeware.net



Ryan Stewart wrote:

Is tehre an easy calculation i can use to convert the integer active
directory stores the setpwdlast value in? I believe it is in
filetime format....
 
Oh Windows will be fine... It is the UNIX people converting filetime to ctime
and then converting that to strings...
 
Back
Top