Converting integer8 from ActiveDirectory to date 
Author Message
 Converting integer8 from ActiveDirectory to date

The windowsforms group could not answer this so I hope there are smarter
people here!

From Active Directory I get a date value as an Integer8 (for example
126631013779284324).
How can I convert this to and from a datetime????

TIA
Peter



Sat, 23 Oct 2004 14:09:53 GMT  
 Converting integer8 from ActiveDirectory to date
if  126631013779284324 = 2002-04-12T18:09:37  try:

DateTime dt = DateTime.FromFileTime( 126631013779284324 );

and note local / UTC diffs?

--
  NETMaster  (Thomas Scheidegger)
  http://www.cetus-links.org/oo_CSharp.html

Quote:

> The windowsforms group could not answer this so I hope there are smarter
> people here!
> From Active Directory I get a date value as an Integer8 (for example
> 126631013779284324).
> How can I convert this to and from a datetime????



Sat, 23 Oct 2004 16:38:28 GMT  
 Converting integer8 from ActiveDirectory to date
Tried it but can't find a working cast. The direct use as your example
doesn't work because there's no impicit cast from the INTEGER8 I get as
input (date from Active Directory).
DateTime.FromFileTime( (long)126631013779284324 ) is not accepted as a valid
cast.
So I'm still looking for a way to get from/to Active Directory.....


Quote:
> if  126631013779284324 = 2002-04-12T18:09:37  try:

> DateTime dt = DateTime.FromFileTime( 126631013779284324 );

> and note local / UTC diffs?

> --
>   NETMaster  (Thomas Scheidegger)
>   http://www.cetus-links.org/oo_csharp.html




- Show quoted text -

Quote:
> > The windowsforms group could not answer this so I hope there are smarter
> > people here!
> > From Active Directory I get a date value as an Integer8 (for example
> > 126631013779284324).
> > How can I convert this to and from a datetime????



Sat, 23 Oct 2004 17:40:42 GMT  
 Converting integer8 from ActiveDirectory to date
read this thread
  http://groups.google.com/groups?threadm=OACdmn5wBHA.2368%40tkmsftngp02

--
  NETMaster  (Thomas Scheidegger)
  http://www.cetus-links.org/oo_csharp.html

Quote:

> Tried it but can't find a working cast. The direct use as your example
> doesn't work because there's no impicit cast from the INTEGER8 I get as
> input (date from Active Directory).
> DateTime.FromFileTime( (long)126631013779284324 ) is not accepted as a valid
> cast.
> So I'm still looking for a way to get from/to Active Directory.....



Sat, 23 Oct 2004 17:52:03 GMT  
 Converting integer8 from ActiveDirectory to date
This is propably an error in the AD integration.

We had it too some time ago with the Active Directory user object.

We then used a generic object and property get to read the data and got -
the correct DateTime instance back.

Do ou have SP1 isnstalled? IMHO in SP1 this should have been handled.

--
Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsft MVP C#/.NET)


Quote:
> Tried it but can't find a working cast. The direct use as your example
> doesn't work because there's no impicit cast from the INTEGER8 I get as
> input (date from Active Directory).
> DateTime.FromFileTime( (long)126631013779284324 ) is not accepted as a
valid
> cast.
> So I'm still looking for a way to get from/to Active Directory.....



> > if  126631013779284324 = 2002-04-12T18:09:37  try:

> > DateTime dt = DateTime.FromFileTime( 126631013779284324 );

> > and note local / UTC diffs?

> > --
> >   NETMaster  (Thomas Scheidegger)
> >   http://www.cetus-links.org/oo_csharp.html



> > > The windowsforms group could not answer this so I hope there are
smarter
> > > people here!
> > > From Active Directory I get a date value as an Integer8 (for example
> > > 126631013779284324).
> > > How can I convert this to and from a datetime????



Sat, 23 Oct 2004 17:56:13 GMT  
 Converting integer8 from ActiveDirectory to date
An "Integer8" in AD is an object holding two 32 bit properties, called LowPart and HighPArt.
Such a property is returned as an generic RCW (__ComObject), what you need to do is unwrap the underlying object or just cast it to
a LargInteger COM type.
After that you have to combine both properties into a long (64 Bit), if the value represents a date you have to translate the format
from FileTime to DateTime.

Following shows how to retrieve "lastLogon" date property.
!!! Set a reference to the activeds.tlb, or create an interop library using tlbimp.exe !!!!
// Use a cast ...
 li = pcoll["lastLogon"].Value as LargeInteger;
 // Or use CreateWrapperOfType
// li =  (LargeIntegerClass)Marshal.CreateWrapperOfType(pcoll["lastLogon"].Value, typeof(LargeIntegerClass));
// Convert to a long
 long date = (((long)(li.HighPart) << 32) + (long) li.LowPart);
// convert date from FileTime format to DateTime
 string dt = DateTime.FromFileTime(date).ToString();
...

Willy.

Quote:

> The windowsforms group could not answer this so I hope there are smarter
> people here!

> From Active Directory I get a date value as an Integer8 (for example
> 126631013779284324).
> How can I convert this to and from a datetime????

> TIA
> Peter



Sat, 23 Oct 2004 20:02:02 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Q: Need algorithm to convert date-time to Julian date

2. Q: convert date to lunar calendar date.

3. Convert Formatted Date-String to Date Object

4. ActiveDirectory

5. ActiveDirectory+ C#

6. ActiveDirectory search

7. Creating new ActiveDirectory object with C#

8. Convert date/time to...

9. Convert a date string

10. Convert date format for Win95 and WinNT

11. Problem converting char date to int sec

12. converting a date string to time_t

 

 
Powered by phpBB® Forum Software