Support Topics Documentation Slack YouTube Blog

Problem retrieving dates from table Android

(Johan Jurrius) #1

I have a small problem with a query:
user = ‘’ and farmName = ‘Farm1’ and rainDate >= ‘21-Nov-2018’ and rainDate <= '21-Nov-2018’
This is the whereClause
If I only want the data for the specific day (in this case the 21st of Nov) how would I do that?
In the Android app the user gives 2 dates. A start and end date. These are the 2 I entered. So if the user chooses the same date as begin and end, how would I display then only that date’s data?
seems as if the = sign is not applied in the clause

(Johan Jurrius) #2

If I use this clause:
user = ‘’ and farmName = ‘Farm1’ and rainDate >= ‘21-Nov-2018’ and rainDate <= '24-Nov-2018’
It will also not send back the 21st’s data.

(Sergey Chupov) #3

Generally speaking, to get the data for 21st of November you need to use this where clause:

rainDate >= 1542758400000 and rainDate <= 1542844800000

where the numbers correspong to timestamps in milliseconds of Nov, 21 00:00:00 and Nov, 22 00:00:00. Note that the dates should be in UTC because that’s how they’re stored in the database.

(Johan Jurrius) #4

Great thanks! Worked perfectly!

For others reading this:

used java.util.Date

On the date object, use getTime() method to get it as a long value for milliseconds.