How to change the date format for the auth records?

29 views
Skip to first unread message

Davidiam

unread,
Aug 14, 2025, 4:14:40 AMAug 14
to py4web
I am getting the US date format in the auth_user tables.  Is there a way to change the format or, even better, to change the default date format for py4web?


Massimo DiPierro

unread,
Aug 14, 2025, 4:47:42 AMAug 14
to Davidiam, py4web
Every validator has a format field. For example IS_DATETIME(format='%Y-%m-%d %H:%M:%S').
To have a default for all of them it would have to be passed explicitly which is not practical. But It can be set after tha facts. For example:

db.define_table("thing", Field("name"), auth.signature)
db.thing.created_on.requires.other.format = '%Y-%m-%d %H:%M:%S'

No depends on whether the validator is a list or IS_NULL_OR(IS_DATETIME(...)) etc. the syntax could be different

db.TABLE.FIELD.requires.format = '%Y-%m-%d %H:%M:%S' (if requires=IS_DATETIME())
db.TABLE.FIELD.requires[0].format = '%Y-%m-%d %H:%M:%S' (if requires=[IS_DATETIME()])
db.TABLE.FIELD.requires.other.format = '%Y-%m-%d %H:%M:%S'(if requires=IS_NULL_OR(IS_DATETIME()))

One could make a function that takes DB, loops over all tables and fields and requires and sets them all for IS_DATE and IS_DATETIME objects.
This would happen only once after table definition at startup.

For example:

def set_format(db, format_date, format_datetime):
    for table in db:
        for field in table:
            if fiel.type=="date' or field.type=''datetime':
                 requires = field.requires
                 if isinstance(requires, list) and len(requires)>0: requires= requires= requires[0]
                 if hasattr(requires,"other"): requires=requires.other
                 if isinstance(requires, IS_DATE): requires.format = format_date
                 if isinstance(requires, IS_DATETIME): requires.format = format_datetime

Maybe there is a better solution but this should work.

Massimo




On Thu, 14 Aug 2025 at 01:14, Davidiam <david....@gmail.com> wrote:
I am getting the US date format in the auth_user tables.  Is there a way to change the format or, even better, to change the default date format for py4web?


--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/py4web/b5654acc-c936-4a78-8c18-055a039810a8n%40googlegroups.com.

Davidiam

unread,
Aug 14, 2025, 7:22:35 AMAug 14
to py4web
Thanks, that is very helpful.

Massimo DiPierro

unread,
Aug 14, 2025, 9:23:42 AMAug 14
to Davidiam, py4web
Please let me know if it works as intended or not. I have not fully tested although should work.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages