Free Android app covering all aspects of addiction, including prevention and treatment

Comparing two dates in Android

I was busy doing some Android coding and needed to compare two dates. The result of the comparison had to show whether the dates were the same or whether one was greater than the other (or smaller). Having stored the dates as an integer in a SQLite database, I extracted and converted them into long objects. It was these long objects that I had to compare. 

As the long objects were accurate time stamps in milliseconds (including hours, minutes, seconds, and milliseconds), this posed a problem when comparing the dates as the same dates would not register as being equal if they differed by even a millisecond! The solution was to first convert them into a format that only represented the day, month and year.