1

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.

OmaL
  • 5,037
  • 3
  • 31
  • 48
dccdany
  • 826
  • 7
  • 17
  • check http://stackoverflow.com/questions/14524322/how-to-convert-a-date-string-to-different-format-in-python – OmaL Aug 26 '14 at 07:05

1 Answers1

3

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.

sepulchered
  • 814
  • 7
  • 18
  • Thank you very much! found no info for this at all till you helped – dccdany Aug 22 '14 at 18:39
  • 1
    If you need the format OpenERP uses for dates to parse or format them for writes etc., import DEFAULT_SERVER_DATE_FORMAT from openerp.tools. Note there also methods on fields.date for converting to the user's timezone. – Adrian Merrall Aug 25 '14 at 04:11