-1

Start time is in format datetime with :

YYYY-MM-DDTHH:MM:SS.SSSZ (e.g., 2004-08-04T19:09:02.768Z)

My code

starttime = item['ListingDetails']['StartTime']
present_date = datetime.now() - timedelta(days=2)
startdate = datetime.strptime(starttime, 'WhichFormat')
if  startdate.date() < present_date.date():
    print('Relisting item :', str(itemid), starttime)

Is throwing the exception because i dont know which was the real format.

Goal is to see if start time is 2 days ago. I.E If item was relisted 2 days ago + then relist it now

azro
  • 53,056
  • 7
  • 34
  • 70
  • I think yo get data from database and format does not match the python datetime format. check this SO answer [https://stackoverflow.com/a/10944136/3210415](https://stackoverflow.com/a/10944136/3210415) – Nicolae May 01 '20 at 15:02
  • Does this answer your question? [converting-string-into-datetime](https://stackoverflow.com/questions/466345) – stovfl May 01 '20 at 15:16

1 Answers1

1

If I understand correctly, you can use dateutil.parser:

import dateutil.parser

starttime = item['ListingDetails']['StartTime']
present_date = datetime.now() - timedelta(days=2)
startdate = dateutil.parser.parse('2004-08-04T19:09:02.768Z')
if  startdate.date() < present_date.date():
    print('Relisting item :', str(itemid), starttime)
kerloom
  • 60
  • 6