Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4668 Lượt xem

I want to get the weekday of a date allocated in the "date_invoice" variable

ex..

date_invoice = 30/01/2018

weekday = 5


thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
Hello \Luis Fuentes,

date_invoice ='30/01/2018'

from datetime import datetime

#1) if you are receiving date in string format then try this,

datetime.strptime(date_invoice,'%d/%m/%Y').isocalendar()[1]

#2)  if its in date format then try this,

date_invoice.isocalendar()[1]

Seems like in your case solution 1) will work perfectly.

Many Thanks.





Ảnh đại diện
Huỷ bỏ
Tác giả

Forgot to mention that I'm using odoo studio to customize this

Related field: Empty

Dependencies: date_invoice

Calculate

for record in self:

record["x_semanum"]=datetime.strptime(date_invoice,'%d/%m/%Y').isocalendar()[1]

none of both options worked, am I doing something wrong?