格式化相关的日期时间字段

时间:2015-09-30 08:14:11

标签: python openerp odoo openerp-6

我有一个相关的日期时间字段

'expected_date'     : fields.related('picking_id','date',type='datetime', relation='stock.picking', store=True, string="Date"),

然后我想在某个报告中显示该字段,但我想使用此代码更改字段的格式

'picking_date' : datetime.strftime(datetime.strptime(str(expected_date), '%Y-%m-%d %H:%M:%S'),'%d-%m-%Y'),

然后我收到了这个错误

时间数据'无'与格式'%Y-%m-%d%H:%M:%S'

不匹配 你能告诉我哪里出错吗?我正在使用openerp6

1 个答案:

答案 0 :(得分:2)

expected_date可能是None,因此str(expected_date)会返回字符串值"None",因此错误不匹配。

你可能想要

'picking_date' : (expected_date is not None
    and datetime.strftime(datetime.strptime(str(expected_date), '%Y-s%m-%d %H:%M:%S'),'%d-%m-%Y')
    or 'None'),