user5256523
user5256523

Reputation:

How can I format date in Odoo 10 QWeb report?

t-field-option is not working.

I have tried

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

Upvotes: 9

Views: 31330

Answers (6)

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.

Upvotes: 2

spacebiker
spacebiker

Reputation: 3865

To display localized date strings. Try the following:

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

Upvotes: 3

Tirtha R
Tirtha R

Reputation: 1318

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

Upvotes: 5

Perino
Perino

Reputation: 628

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!

Upvotes: 8

Abhay Singh Rathore
Abhay Singh Rathore

Reputation: 179

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.

Upvotes: 0

Er.Ankit H Gandhi
Er.Ankit H Gandhi

Reputation: 656

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

Upvotes: 0

Related Questions