Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
26152 มุมมอง

Hi everyone,

I want to extract just the date from create_date field in the account.invoice model.

I tried t_date = datetime.datetime.strptime(record.create_date, '%Y-%m-%d') and bunch of other options but none worked. 
Kindly help, it's for Odoo online Saas version, in particular to the automated actions.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

If above answer give you error "ValueError: unconverted data remains" or doesn't work

Try:

from dateutil import parser
datetime_obj = parser.parse('2018-02-06T13:12:18.1278015Z')

Hope it help.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Dear Shaheryar Rajper,

 Try this:

from datetime import date, datetime,

t_date= datetime.strptime(record.create_date, "%Y-%m-%d %H:%M:%S").date()


I hope I helped You...

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Hi Ayman,

I get this error "<class 'AttributeError'>: "module 'datetime' has no attribute 'strptime'" while evaluating"
then if I change it to t_date= datetime.datetime.strptime(record.create_date, "%Y-%m-%d %H:%M:%S").date() I get "Can't convert 'datetime.date' object to str implicitly" while evaluating
I am using Odoo Saas automated actions, date and datetime are available so I dont need to import


Edit:

The correct way of doing it is
t_date= datetime.datetime.strptime(record.create_date, "%Y-%m-%d %H:%M:%S").strftime('%Y-%m-%d')
hopefully it helps others as there is lack of Saas support

อวตาร
ละทิ้ง

Make Print to ensure that is not null.

print " DDDDDDDDDD ", record.create_date

ผู้เขียน

i cannot do a print so i added it to a raise Warning and it works :)

ผู้เขียน

This is my code

t_date= datetime.datetime.strptime(record.create_date, "%Y-%m-%d %H:%M:%S").strftime('%Y-%m-%d')

if (t_date > record.date_invoice) :

raise Warning("Payment Date "+record.date_invoice+" cannot be before than the Donation Date"+" "+t_date)

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 24
13970
0
ก.พ. 22
2430
1
ก.ค. 21
8108
0
เม.ย. 20
4673
1
พ.ค. 18
2951