I have a table containing records with DateTime datatype in MySQL (e.g. 2013-01-17 21:16:06),
while on my entity I choose LocalDateTime datatype for the date field. During my queries I would like to retrieve all records based on 2 Dates only (fromDate and toDate using a datepicker). Lets say I choose the same date for both fromDate and toDate, the issue is both value would be the same since the time is 00:00:00, hence gives no result from the database.
I am curious if I have used the right datatype from Joda. Am I required to adjust the time for both values lets say 00:00:00 for fromDate and 23:59:59 for toDate ? Or what’s the better approach ?
Given a datetime column and two arbitrary dates as input, you can write:
Where:
What the above means is best explained through the following cases:
2013-01-17(one day) startDate should be2013-01-17and endDate should be2013-01-172013-01-17–2013-01-18(two days) startDate should be2013-01-17and endDate should be2013-01-18.This makes choosing the dates intuitive. The
<sign ensures that the calculated end date is excluded from the results (e.g. in the first case the query omits `2013-01-18 00:00:00 records).