Web2py Python formatting date

I am looking for a function to format dates to get day, month, and year. Dates are stored in my database in the following format 2012-09-26.

+4
source share
1 answer

If your goal is to render on a web2py template, you need to use pure Python to format

{{=row.datetime_field.strftime("%d/%m/%Y")}} 

The above will generate 25/09/2012

Tell us about Python strftime docs.

If you want to show only the day.

 {{=row.datetime_field.date}} 

You can also set it as a view for this field.

 db.mytable.datetime_field.represent = lambda value, row: value.strftime("format-here") 

The view will only be useful for SQLFORM.grid and SQLTABLE

All you need is strftime

+10
source

Source: https://habr.com/ru/post/1436414/


All Articles