Shravy
Shravy

Reputation: 666

How to fix format mismatch error in odoo?

I have been trying with this code

def onchange_date(self, cr, uid, ids, fdate, context=None):
    if fdate:
        if datetime.strptime(fdate, '%Y %m %d %H:%M:%S').date() > datetime.now().date():
            return { 'value': { 'fdate': False } }
        return fdate

and I am getting this error

ValueError: time data '2015-07-25 06:24:46' does not match format '%Y %m %d %H:%M:%S'

Upvotes: 1

Views: 779

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11141

Replace this code

if datetime.strptime(fdate, '%Y %m %d %H:%M:%S').date() > datetime.now().date():

with to

if datetime.strptime(fdate, "%Y-%m-%d %H:%M:%S").date() > datetime.now().date():

Upvotes: 2

Related Questions