Reputation: 6802
In my local setup i'm using a simple H2 databse. The "hosted" solution will have another (similar but not same) database.
I need to insert the maximum possible date into a DateTime column. I tried to use
Instant.MAX
However this results in -169104626-12-11 20:08:15.99999999 in the column.
Is there a solid option on how to insert a maximum possible date?
Upvotes: 3
Views: 1609
Reputation: 338730
max date (independent from database)
No such thing. Trying to set a maximum date is absolutely dependent on the database.
The topic of date-time handling is barely touched by the SQL standard (unfortunately). The data types and behavior for date-time vary widely amongst various databases. The minimum and maximum values can be radically different between various databases. Even within a single database, the min/max range of the various date-time data types can be dramatically different. For example, some databases have old proprietary date-time types as well as newer more common or standard types that behave quite differently.
Java itself has very different sets of date-time types:
The min/max of these differ.
Is there a solid option on how to insert a maximum possible date?
No.
If you are trying to use the maximum value as some kind of flag such as "undetermined future date" to avoid a NULL, instead choose some arbitrary date far enough in the future to exceed any legitimate value but not so far as to exceed the limits of any database you are possibly going to use. Define a constant for this value in your Java code and in your database, and document thoroughly.
I suggest sticking with a four-digit year to avoid all kinds of confusion and problems such as breaking reports & GUIs by exceeding the field’s width of display. Something like 9999
. Or perhaps 2666
because it is so noticeable to the human reader due to the infamy of 666.
Search Stack Overflow for words such as Java, min, and max, for more discussion. Like this and this and this and this and this. This question is basically a duplicate of other Questions.
Upvotes: 4