Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I format date in Odoo 8 QWeb report?

The date in my Sales Order is currently showing as:

Fecha: 21/11/2014 16:59:15 

I want to show something like this:

Fecha: Surco, 21 de Noviembre del 2014

I tried using t-esc with strftime but that doesn't work:

<span t-esc="o.date_order.strftime('%Y')" />
like image 746
César Avatar asked Nov 21 '14 22:11

César


2 Answers

Try using:

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

Result: 21 Noviembre 2014

like image 189
Sebastian Avatar answered Oct 02 '22 06:10

Sebastian


It seems like o.date_order it's not a datetime object but a string. Using the time module is the way to go:

<span t-esc="time.strftime('%A, %d %B %Y',time.strptime(o.date_order,'%Y-%m-%d %H:%M:%S'))"/>
like image 20
César Avatar answered Oct 02 '22 06:10

César