繁体   English   中英

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

[英]Formatting related datetime field

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

'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。

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'),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM