CloseISQ
CloseISQ

Reputation: 353

OpenERP 6.1 datetime formatting

Why does

o.create_order.strftime("%d %B %Y")

returns nothing when

time.strftime("%d %B %Y")

returns the date "10 february 2013"???

o.create_order is a timestamp according to postgresql. It contains "30/11/2012 09:38:34" as seen on the openErp sale order - Other information tab. It is stored as "2012-11-30 08:38:34.272" when querying the database. So I would expect to see "30 November 2012" but get nothing instead. Am I misinterpreting the syntax?

I tested this from python 3.3:

>>> d1=datetime.datetime.today()
>>> print(d1.strftime("%d %B %Y"))
10 february 2013 

How do I get it to work in OpenOffice Writer?

And by the way how do I get "February" instead of "february"?

Upvotes: 1

Views: 2571

Answers (2)

Sudhir Arya
Sudhir Arya

Reputation: 3743

It is because o.create_order returns a string. So first you have to convert your string date into datetime format and then again you can convert it into any format you want as a string.

Try this:

#Converts string into datetime format. dt1 = datetime.strptime(o.create_order,"%Y-%m-%d %H:%M:%S")

#Converts datetime into your given formate and returns string. dt2 = datetime.strftime(dt,"%d %B %Y")

Hope this will solve your problem.

Upvotes: 0

Oli
Oli

Reputation: 15932

Because o.create_order returns a string and not a datetime object, even if, internally, the database column is a timestamp. The OpenERP ORM returns a string in ISO 8601 format.

You need to use the formatLang method which is available in RML reports or create a datetime object using the datetime python module.

Try this:

datetime.strftime('%d %B %Y', o.create_order')

Upvotes: 1

Related Questions