6
votes

t-field-option is not working.

I have tried

<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>
6

6 Answers

6
votes

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!

3
votes

To display localized date strings. Try the following:

<span t-field="o.date_invoice" t-options="{&quot;widget&quot;: &quot;date&quot;}" />
2
votes

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

2
votes

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.

0
votes

Try this.

<span t-esc="datetime.datetime.strptime(o.sale_id.confirmation_date, '%Y-%m-%d %H:%M:%S').strftime('%B %d,%Y')"/>

My Output is: May 28,2018

0
votes

According to my experience, you have used the correct way to format Qweb date, but sometimes there is problem in other thing and odoo gives error somewhere else. Hope trying this code may be helpful.

<span t-field="o.date_order" t-field-options='{"format": "d MMMM y"}'/>

also use this code

<span t-field="o.date_order" t-field-options="{'format': 'yyyy-MM-dd'}" />

You can also do one thing as formatting the date variable in the model itself and then show it on your QWeb report.