May-03-2020, 01:32 AM
(May-03-2020, 01:24 AM)snippsat Wrote: When you shall compare dates you need eg stringstr(row[2]
to be adatetime
object.
Here i quick demo,and i use Pendulum because it's great and build on top of datetime,just doing stuff better.
>>> import pendulum >>> >>> s = 'Beltway, 2020-04-30 23:18:14' >>> my_date = s.split(', ')[1] >>> my_date '2020-04-30 23:18:14' >>> type(my_date) <class 'str'> # Can parse a string automatically >>> my_date = pendulum.parse(my_date) >>> my_date DateTime(2020, 4, 30, 23, 18, 14, tzinfo=Timezone('UTC')) >>> type(my_date) <class 'pendulum.datetime.DateTime'> # Now that is a datetime object can compare,eg just use yesterday as a example >>> yesterday = pendulum.yesterday() >>> yesterday DateTime(2020, 5, 2, 0, 0, 0, tzinfo=Timezone('Europe/Berlin')) >>> >>> my_date < yesterday True >>> my_date == yesterday False >>> my_date <= yesterday True >>> my_date >= yesterday False
Thank you so I see what can be say a hard code date, will I need to manually update or change this daily or is it possible to say like today minus 1 to equal the output or am I looking/thinking and making this way more complicated? Sorry this is all new to me and first time comparing a date that’s in the past hope what I’m trying to do makes sense