tags:

views:

1965

answers:

4

is there a function like getdate() in ms sql server 2005 that let's you get the max possible date?

i do NOT want to find the highest date in a table. i want to get the max possible date that sql server will be able to store. basically, i want an expiration date of never

A: 

Consult the documentation.

http://msdn.microsoft.com/en-us/library/ms187819.aspx

Date range
January 1, 1753, through December 31, 9999

There is no way to get the max datetime programatically.

If so it would be listed here:

http://msdn.microsoft.com/en-us/library/ms186724.aspx

magnifico
A: 

January 1, 1753, through December 31, 9999

Zerofiz
A: 

The documentation says the range is January 1, 1753, through December 31, 9999.

I don't think there is a built in function, but you could create one that returns the maximum datetime value.

CREATE FUNCTION fn_max_date
RETURNS datetime
AS
return cast('12/31/9999' as datetime)
scottm
I've always thought these were very odd choices. I'd much rather be able to use years before 1753 rather than years after, say, 2400.
Joel Coehoorn
I think its because of problems with which countries switch to Gregorian calendar for dates earlier than 1753
Kristen
The accuracy is also strange, the documentation says it's "Rounded to increments of .000, .003, or .007 seconds"
scottm
Kristen is correct, one of the reasons for not allowing dates older than 1753 is because calendars weren't standard back then.datetime data types round to 3ms in SQL Server. For greater control use the new data types in SQL 2008+.
mrdenny
A: 

If you truly want an expiration date of "never", it might be better to store NULL rather than an arbitrary far-future date. While it is unlikely that the date will reach year 9999 without the code being "fixed", it is an illogical value to store for EndDate = never.

Cadaeic