8

t-field-option is not working.

I have tried

<span t-field="o.date_invoice" t-field-options='{"format": "MM/dd/yyyy"}'/>
Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58

6 Answers6

8

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!

Perino
  • 608
  • 9
  • 30
  • In v12, the date/datetime fields are python date/datetime objects and not string representations. The following python formatting will work in v12: . https://www.odoo.com/groups/technical-62/technical-56392463 – Tirtha R Aug 09 '19 at 10:25
  • @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. – Loïc Faure-Lacroix Jan 15 '20 at 19:52
4

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

Tirtha R
  • 1,148
  • 1
  • 14
  • 24
  • 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! – Patrick Aug 21 '19 at 08:02
  • what does one have to type in order to get the month spelled out instead of it being just numbers? – unnamed-dev Nov 21 '22 at 14:11
  • Try `MMM` or `MMMM`. – Tirtha R Dec 01 '22 at 15:32
3

To display localized date strings. Try the following:

<span t-field="o.date_invoice" t-options="{&quot;widget&quot;: &quot;date&quot;}" />
spacebiker
  • 3,777
  • 4
  • 30
  • 49
2

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

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

Pang
  • 9,564
  • 146
  • 81
  • 122
  • Error to render compiling AST TypeError: strptime() argument 1 must be str, not datetime.date I get this error. Can you pls help – BomberMan Aug 20 '20 at 16:51
0

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.

Nwawel A Iroume
  • 1,249
  • 3
  • 21
  • 42