No Such Thing As ‘End Of Day’
The problem with your question and all the answers is the definition of the end of day. You cannot pin down the end of day, as there are infinite fractions of a second between the last second of the day and the first moment of the new day.
You may think you can compensate for that. One answer talked about java.sql.Date eliminating minutes and seconds, which is true - but you likely need the time as part of your values. Another answer talked about using three decimal places of a fraction of a second. But different databases save a different number of decimal places, so you are building in a fragile assumption. The new java.time.* classes in Java 8 use nanosecond time resolution, which means your app may have instances that represent moments happening after your three-digit decimal place limit.
Use New Day
The proper way to represent a span of time is to record:
- Moment when span starts
- Moment after span ends
You are missing the "after" part of that second item.
The stop time, the deadline in your case, should be the first moment of the new day. The valid period, before the expiration/deadline, includes all the infinitely fine moments happening up until that new day. By marking the Stopping point as the new day, you can write the logic of your app & queries as…
Is the moment in question GREATER THAN OR EQUAL
to the Start AND
is it LESS THAN
the Stop?
Notice that the second part of that does not contain OR EQUAL TO
. Now you are accounting for all fractions of a second between the last second of day and the first moment of the new day.
To illustrate, here is a diagram of how to define a week. This is taken from my answer to another question, Get the week start and end date given a current date and week start.

Joda-Time
In Java work, avoid using java.util.Date & Calendar classes. Instead use Joda-Time or the new java.time.* classes in Java 8 (inspired by Joda-Time).
First Moment
Do not assume the new day starts at 00:00:00. Some time zones start Daylight Saving Time (DST) at the stroke of midnight, moving the hands of the clock to something like 01:00. Joda-Time includes a method for this very purpose of determining the first moment of the new day: withTimeAtStartOfDay
. That method is smart, handling anomalies such as DST beginning at midnight. The midnight-related methods in Joda-Time have been deprecated or no longer recommended.
DateTime tomorrow = new DateTime().plusDays( 1 ).withTimeAtStartOfDay();
Time Zone
Actually, a better practice is to always specify a time zone rather than rely on default. So I would use code more like this…
DateTime tomorrow = new DateTime( DateTimeZone.forId( "Europe/Paris" ) ).plusDays( 1 ).withTimeAtStartOfDay();
Or, if using UTC/GMT (no time zone offset)…
DateTime tomorrow = new DateTime( DateTimeZone.UTC ).plusDays( 1 ).withTimeAtStartOfDay();
DateTime ↔ Date
You can easily convert between Joda-Time and java.util.Date as needed for exchanging data with other classes. Pass a Date to Joda-Time constructor. Going the other way, call the toDate()
method in Joda-Time.
To…
DateTime myDateTime = new DateTime ( myDate );
and fro…
java.util.Date myDate = myDateTime.toDate();