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="{&quot;widget&quot;: &quot;date&quot;}" />

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.

Share:
25,317
Admin
Author by

Admin

Updated on October 24, 2020

Comments

  • Admin
    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
    Tirtha R almost 5 years
    In 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
    Patrick almost 5 years
    This 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. Using widget="date" solved the problem. Thanks!
  • spacebiker
    spacebiker over 4 years
    Note to Editors: Please DO NOT EDIT &quot; as this is how it should be added in the qweb editor, thanks
  • Loïc Faure-Lacroix
    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
    BomberMan almost 4 years
    Error to render compiling AST TypeError: strptime() argument 1 must be str, not datetime.date I get this error. Can you pls help
  • NM Naufaldo
    NM Naufaldo about 2 years
    I think we should use t-options instead of t-field-options