ValueError: unconverted data remains: 00:00:00
Asked Answered
P

3

7

I have problem in convert date time.

Here is my code:

@api.multi
def action_confirm(self):
if picking.state not in ['cancel', 'draft']:
    for schedule_delivery in sorted_key:

    print "line 105: ", schedule_delivery
                dup_picking = picking.copy()
                        if shift == "afternoon":
                            date_object = datetime.strptime(schedule_delivery, '%Y-%m-%d')
                            print "Line 146", date_object
                            # raise EnvironmentError
                            tanggal = datetime.strftime(date_object, "%Y-%m-%d") + ' 06:00:00'
                            print "Line 145", tanggal
                            dup_picking.min_date = tanggal
                        else:
                            dup_picking.min_date = schedule_delivery

Error:

    date_object = datetime.strptime(schedule_delivery, '%Y-%m-%d')
  File "/usr/lib/python2.7/_strptime.py", line 328, in _strptime
    data_string[found.end():])
ValueError: unconverted data remains:  00:00:00
Perdition answered 21/11, 2017 at 3:26 Comment(1)
You could do this, datetime.strptime(str(schedule_delivery), '%Y-%m-%d ')Ctenidium
W
10

You can use this line of code-

date_object = datetime.strptime(str(schedule_delivery), '%Y-%m-%d %H:%M:%S')
Wrack answered 21/11, 2017 at 3:40 Comment(0)
S
2

i know its was asked a long time ago, i hope its still relevant.

in order to avoid the remains of the time format you need to convert your datetime to date

this is the code that solved this issue for me:

self.start_date=str((datetime.strptime(str(self.start_date), '%Y-%m-%d')+timedelta(nDays)).date())

Blockquote

Scutcheon answered 25/12, 2022 at 18:52 Comment(0)
T
-2

Change the date to a pandas date:

Time object e.g

a = pd.to_datetime(df['date']).apply(lambda x: x.date())

Then

date_object = datetime.strptime(str(schedule_delivery), '%Y-%m-%d')
Tippett answered 18/9, 2020 at 0:0 Comment(1)
pandas is overkill to deal with simple stuff like thisCatlee

© 2022 - 2024 — McMap. All rights reserved.