I have date and time stored in "yyyy-mm-dd HH:mm" format in my Rooms Database as a String. I want to get the data in descending order of date and time from my Rooms database, however since it is in String format, how can I achieve that?
Asked
Active
Viewed 180 times
1
-
1The format of your dates is fine and you can use it as it is. – forpas Mar 07 '21 at 15:26
-
Yes it works, but you upvoted a misleading answer. – forpas Mar 07 '21 at 18:03
-
@forpas how can I downvote that? I have flagged for moderator's attention so that it can be edited/looked into by the answer provider/moderator. – Ian Bell Mar 07 '21 at 18:37
-
You can't downvote it once you upvoted it, unless it is edited. Just note that you don't have to upvote all the answers you get. If they are useful then do it. If not then don't. – forpas Mar 07 '21 at 18:42
-
@forpas got it, will keep that in mind, thanks! :) – Ian Bell Mar 07 '21 at 18:56
1 Answers
-1
As the format is sortable as it stands you simply have to sort it as is, that is nothing special needs to be done.
The following is an example that extracts data from the Autologin entity(table) sorted according to the expiration_date column in descending order :-
@Query("SELECT * FROM AutoLogin ORDER BY Autologin.expiration_date DESC")
AutoLogin[] getLoginsSortedByExpirationDate();
Obviously you'd change the above to suit your project/app.

MikeT
- 51,415
- 16
- 49
- 68
-
It is not useless, it answers the questions and provides an example of how to actually code a sort. – MikeT Mar 08 '21 at 18:29
-
Ask questions, **get answers**, no distractions This site is all about getting answers. It's not a discussion forum. There's no chit-chat. https://stackoverflow.com/tour – MikeT Mar 08 '21 at 18:38
-
The answer was provided in the comments because **there is no problem**. You admit this when you say **nothing special needs to be done**. The asker realized that there is nothing to change because **everything is fine as it is**. So there is no need to post as answer what is already been discussed with an example that has nothing to do with the OP's code. – forpas Mar 08 '21 at 18:53
-
Ask questions, get answers, no distractions This site is all about getting answers. It's not a discussion forum. There's no chit-chat. stackoverflow.com/tour – MikeT Mar 08 '21 at 19:23
-
-
If you were to only post constructive matter then there would be no need to remind you of the purpose of the site. – MikeT Mar 08 '21 at 19:28