How can I format date in Odoo 10 QWeb report?
25,317
Solution 1
Instead of using
<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>
use
<span t-field="o.date_invoice" t-options='{"format": "MM/dd/yyyy"}'/>
Hope that helps!
Solution 2
To display localized date strings. Try the following:
<span t-field="o.date_invoice" t-options="{"widget": "date"}" />
Solution 3
For those who arrive here from search engines, you can control display of date in form fields using widgets.
<field name="date_planned" widget="date"/>
or,
<field name="date_planned" widget="datetime"/>
In v12, the date/datetime fields are python date/datetime objects and not string representations. The following python formatting will work in v12 reports:
<span t-esc="o.date_invoice.strftime('%m/%d/%Y')"/>
https://www.odoo.com/groups/technical-62/technical-56392463
Solution 4
To delete the time section:
<span t-field="o.date_invoice" t-field-options='{"widget": "date"}'/>
Use t-field-options
instead of t-options
Do not change the position of the quotes in t-field-options
This code respects the format date according to lang/country.
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on October 24, 2020Comments
-
Admin over 3 years
t-field-option is not working.
I have tried
<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>
-
Tirtha R almost 5 yearsIn v12, the date/datetime fields are python date/datetime objects and not string representations. The following python formatting will work in v12: <span t-esc="o.date_invoice.strftime('%m/%d/%Y')"/> . odoo.com/groups/technical-62/technical-56392463
-
Patrick almost 5 yearsThis is exactly what I was looking for! Odoo 12, in the when creating a purchase order in the 'Purchases' app, the datetime widget was adding too much information! I tried
t-options='{"format": "yyyy/MM/dd"}'
but that didn't work. Usingwidget="date"
solved the problem. Thanks! -
spacebiker over 4 yearsNote to Editors: Please DO NOT EDIT " as this is how it should be added in the qweb editor, thanks
-
Loïc Faure-Lacroix over 4 years@TirthaR no it won't work as expected if you run odoo in different languages, strftime format based on the locale and not an arbitrary language.
-
BomberMan almost 4 yearsError to render compiling AST TypeError: strptime() argument 1 must be str, not datetime.date I get this error. Can you pls help
-
NM Naufaldo about 2 yearsI think we should use
t-options
instead oft-field-options