Python Forum
Problem with datetime module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with datetime module
#1
Hello,

i have a csv file. It represents events that happen in France. One column contains date written like so 'YYYY-MM-DD'. I want to delete every row that has a date difference of at least 60 days from today.

I have created this program that from the string 'YYYY-MM-DD' return the difference in days from today.

date ='2018-08-26'
liste = date.split('-')
print(liste)
liste2 = []
liste2.append(int(liste[0]))
liste2.append(int(liste[1].replace('0','')))
liste2.append(int(liste[2].replace('0','')))
print(liste2)
test = datetime.now() -  datetime(liste2[0], liste2[1], liste2[2])
print(test)
if test[0] > 60 :
    print("delete")
And I get this error:

['2018', '08', '26']
[2018, 8, 26]
-33 days, 9:52:04.046700
Traceback (most recent call last):
  File "untitled2.py", line 20, in <module>
    if test[0] > 60 :
TypeError: 'datetime.timedelta' object is not subscriptable
I don't know how to "extract" the number of days, do you have any idea?

Thank you
Reply


Messages In This Thread
Problem with datetime module - by PierreSoulier - Jul-24-2018, 07:56 AM
RE: Problem with datetime module - by buran - Jul-24-2018, 08:19 AM
RE: Problem with datetime module - by perfringo - Jul-24-2018, 11:03 AM
RE: Problem with datetime module - by PierreSoulier - Jul-24-2018, 08:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with memory_graph module akbarza 3 435 Mar-04-2024, 10:15 AM
Last Post: snippsat
  datetime module question jacksfrustration 9 1,908 Jan-12-2024, 04:54 AM
Last Post: deanhystad
  problem using coloeama module akbarza 3 628 Jan-08-2024, 07:31 AM
Last Post: akbarza
  problem in using subprocess module akbarza 5 1,105 Sep-24-2023, 02:02 PM
Last Post: snippsat
  problem in import module from other folder akbarza 5 1,579 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  problem in using pyqrcode module to create QRcode akbarza 9 2,167 Aug-23-2023, 04:17 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,069 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  Problem with module time and leap seconds Pedroski55 3 1,291 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  Problem with datetime [SOLVED] AlphaInc 3 2,954 Apr-22-2022, 01:33 PM
Last Post: snippsat
  2-dataframe, datetime lookup problem Mark17 0 1,265 Jan-27-2022, 01:02 AM
Last Post: Mark17

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020