How to format a datetime data binding

A couple of things to note about your solution.

  1. When you’re in a server function, don’t use anvil.server.call to call another server function, that just adds overhead. Just call the server function like a normal function, e.g.:
@anvil.server.callable
def format_locale_datetime(myDatetime):
  preferred_locale = get_preferred_locale()
  1. The client context isn’t going to change for a user during a session, so you could make that get_preferred_locale call once on startup and cache the value in a client module, and then use client code for the strftime calls, avoiding the overhead of the frequent server calls.

As is, there’s going to be a delay each time you set the text for a datetime because of the server call.

2 Likes