Is there any way to sort by just time and not datetime

0
Hi all,   We’ve got a list of medicine doses that our users can add into our app and I would like to sort these by time in a list view however I’m getting the problem below.   It seems that if a user enters some doses on one day it will list it correctly but if they then add more the next day then it starts to appear out of order because the app is still ordering by date and time instead of just time.    So for example the image above the first two doses were created on 06/10/2022 and last two were created on the 07/06/2022.   Would I have to do this in a source microflow for the listview and if so is there a simple way to do it?   Thanks Nathan
asked
5 answers
2

You could look at creating another attribute that stores the sort order, so when you display the list you can order it by this attribute.

Maybe the easiest way to do this would be to create a new DateTime value with a common date and just copy the time from your existing object to it. Something like this...
 

parseDateTime('2022-01-01 ' + formatDateTime($object/Date1,'HH:mm:ss'), 'yyyy-MM-dd HH:mm:ss')

 
Hope this helps.

answered
3

Hi,

Please separate date & time fields then you can sort it easyly.

https://docs.mendix.com/refguide7/parse-and-format-date-function-calls/

Thanks & Regards

Hi,

Please separate date & time fields then you can sort it easyly.

https://docs.mendix.com/refguide7/parse-and-format-date-function-calls/

Thanks & Regards

answered
1

One of the ways could be to break down the dateTime to date and time separately, sort by time, then by date and put it back together in descending order. 

 

Have you already tried the formatTime function?

 

Parse and Format Date Function Calls | Mendix Documentation

 

 

answered
0

Hi Nathan,

 

Solution could be update datetime of all associated doses on entering new dose everytime. 

 

Please mark answer as Accepted, it helps :)

 

answered
0

If the time component is only relevant in your data; just use integers for hours and minutes separately

Sorting is way more easier, no timezone related issues and displaying can be done using a text widget (1):{2}

{1} Hours

{2} Minutes

answered