finding max possible date in ms sql server 2005+

Viewed 93038

Is there a function like GETDATE() in 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

7 Answers

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 23:59:59.9999' as datetime)

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.

January 1, 1753, through December 31, 9999

Related