Searching a databable based on time/date

Welcome to the forum!

Getting the most recent entry is pretty straightforward, and involves two concepts.

One is asking Anvil to order the results. For example, if your datetime field is when, you could do:

app_tables.log.search(tables.order_by('when', ascending=False))

That gives you the list from the latest date to the earliest date.

The second part is that those results act like a Python list. You know that the most recent date is in the first element of the results, so you can get it like getting the first element of a Python list:

result = app_tables.log.search(tables.order_by('when', ascending=False))
latest = result[0]

That gives you a row, which you can then work with as normal:

self.text_box_2.text = latest['In_out']
1 Like