'Why am I getting the error: 'method_descriptor' object has no attribute 'now'?

If I run the method

from datetime import datetime
from timedelta import time 

def action_retbook(self, cr, uid, ids, context=None): 
    dt = datetime.date.now() 
    todaydate = datetime.strptime(dt, "%y/%m/%d") 
    x=6 
    cr.execute("""update rmkbook_issue set dt_of_return ='%s' where id= %s """ %(todaydate, x)) 
    return

I get the error 'method_descriptor' object has no attribute 'now'. Why?



Solution 1:[1]

You can run the method now() like this:

dt = datetime.now() 

You can check this question as well

Solution 2:[2]

I believe

from datetime import datetime

datetime.now()

Works.. in python 3.9.7

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2