Sort elements by Time

Hello everyone!

I have a question about sorting auctions by date. I am using the Time type, and the time format is yyyy:mm:dd:hh:mm
. When I try to sort by today’s date using Time.now(), it returns the format yyyy:mm:dd:hh:mm
and compares up to the yyyy:mm:dd:hh:mm. However, I need to compare only the day(yyyy:mm:dd) and retrieve only today’s auctions. How can I do this in motoko?

for (auction in a) {
for (auction1 in a) {
if (auction.item.bid > auction1.item.bid) {
id := auction.id;

        };
        if(auction.createdAt == Time.now()){
          id:= auction.id
        }
    };
};
let auction = findAuction(id);
// let bidHistory = List.toArray(List.reverse(auction.bidHistory));
{ item = auction.item; bidHistory = auction.bidHistory; createdAt = auction.createdAt};

This motoko datetime library might be helpful
https://mops.one/datetime

2 Likes