473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Converting AD Expire Date to DateTime

I'm taking the value of the expire date out of an AD account (accountExpires
attribute) and passing it into this function.

static DateTime LargeIntToDateTime(ActiveDs.LargeInteger li)
{
long lTime;
lTime = (long)li.HighPart;
lTime <<= 32;
lTime |= (uint)li.LowPart;
return System.DateTime.FromFileTime(lTime);
}

It worked a month ago, but it seems like on a certain day it started
throwing this exception:

Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.

I'm way out of my element. Could someone hit me with a clue stick.

Nov 16 '05 #1
2 15287
The value of LongInteger is set to 0X7FFFFFFFFFFFFFFF when the account never
expires, this is an invalid value for FromFileTime to convert to a date.
So you need to validate the value before calling FromFileTime, try this...
...
DateTime retDate;
if((li.HighPart == Int32.MaxValue) && (li.LowPart == -1))
{
retDate = DateTime.MaxValue; //never expires - invalid date, return
some meaningful date
}
else {
// Valid date to convert to DateTime format
long date = (((long)(li.HighPart) << 32) + (long) li.LowPart);
retDate = DateTime.FromFileTime(date).ToString();
}
return retDate;
}

Willy.

"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
I'm taking the value of the expire date out of an AD account
(accountExpires
attribute) and passing it into this function.

static DateTime LargeIntToDateTime(ActiveDs.LargeInteger li)
{
long lTime;
lTime = (long)li.HighPart;
lTime <<= 32;
lTime |= (uint)li.LowPart;
return System.DateTime.FromFileTime(lTime);
}

It worked a month ago, but it seems like on a certain day it started
throwing this exception:

Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.

I'm way out of my element. Could someone hit me with a clue stick.

Nov 16 '05 #2
Or simply:
if(li.HighPart == Int32.MaxValue)
{
// invalid date - never expires...
...

Willy.

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
The value of LongInteger is set to 0X7FFFFFFFFFFFFFFF when the account
never expires, this is an invalid value for FromFileTime to convert to a
date.
So you need to validate the value before calling FromFileTime, try this...
..
DateTime retDate;
if((li.HighPart == Int32.MaxValue) && (li.LowPart == -1))
{
retDate = DateTime.MaxValue; //never expires - invalid date, return
some meaningful date
}
else {
// Valid date to convert to DateTime format
long date = (((long)(li.HighPart) << 32) + (long) li.LowPart);
retDate = DateTime.FromFileTime(date).ToString();
}
return retDate;
}

Willy.

"- Steve -" <se****@foundation.sdsu.edu> wrote in message
news:eV**************@TK2MSFTNGP12.phx.gbl...
I'm taking the value of the expire date out of an AD account
(accountExpires
attribute) and passing it into this function.

static DateTime LargeIntToDateTime(ActiveDs.LargeInteger li)
{
long lTime;
lTime = (long)li.HighPart;
lTime <<= 32;
lTime |= (uint)li.LowPart;
return System.DateTime.FromFileTime(lTime);
}

It worked a month ago, but it seems like on a certain day it started
throwing this exception:

Ticks must be between DateTime.MinValue.Ticks and
DateTime.MaxValue.Ticks.

I'm way out of my element. Could someone hit me with a clue stick.


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: sunny076 | last post by:
Hi, I am trying to convert from Julian to Gregorian data in C#. I was exploring teh JulianCalendar and Gregorian calendar classes but still not sure how I can do it. For example, the Julian date...
5
by: Bryan Yeo | last post by:
Trying to get the user password expire date from AD, but there is no such field. What I could get is the PasswordLastChanged property. Is there anyway I could calculate the date or something? ...
3
by: martin | last post by:
Hi, I am storing a dataset in cache, which is happening fine. I can easily retrive it at postback from the cache, cast it to a dataset and reuse it. However I have specified that the cache...
1
by: Andrew Baker | last post by:
this seems to be an SQL Server error but I cant work out how it is occuring. Itr is also after 3am and I cant keep working but need to demo by tomorrow. TIA. The code is: Private Sub...
8
by: Mika M | last post by:
Is there better way to convert integer type date into DateTime type date as doing like code below? Dim intDate As Integer = 20051019 Dim dte As DateTime = New DateTime( _...
3
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
11
by: Keith Hughitt | last post by:
Hi, I am having a little trouble figuring out how to convert a python datetime to UTC. I have a UTC date (e.g. 2008-07-11 00:00:00). I would like to create a UTC date so that when I send it to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.