Reputation: 836
I'm using two dates to form a "period" in openErp:
_columns = {
'date_from': fields.date('From', required = True),
'date_to': fields.date ('To', required = True),
}
These two fields are inputs for the user, after they choose both dates I create a string called "period"
'period': str(date_from)+ ' // ' + str(date_to),
thing is, that the dates are in format "y-m-d" and i need them to be "d-m-y", even if i select my language in openERP it wont changue that string.
Is there any way that i can change that format ?
Thanks in advance.
Upvotes: 1
Views: 6698
Reputation: 814
As I found out when you try to get objects date/datetime field value it's returned as string, so this is ugly but for now (as I haven't seen better method) I do something like:
from dateutil import parser
...
my_date = parser.parse(my_object.date)
proper_date_string = my_date.strftime('%d-%m-%Y')
You also can use python datetime
module and parse date string via strptime
. But dateutil
is required for openerp so you can use it.
Upvotes: 3