I have read this question asked several times but I just can't get rid of the datetime attribute error. Managed to import a csv file and assigned the latest datetime to "LastImportDate". Printed out the dates without issue but encountered error when I added in the if statement to compare "LastImportDate" and "Yesterday". Can advise me what has gone wrong on my script? Thanks in advance.
=====
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
LastTankGaugeBook = pd.read_csv('Final_Tank_Gauge_Book.csv')
LastTankGaugeBook = LastTankGaugeBook.set_index(['Date_Time'])
LastTankGaugeBook = LastTankGaugeBook.sort_index()
LastImportDate = LastTankGaugeBook.index.max()
Today = datetime.today()
Yesterday = Today - timedelta(days=1)
print('Last import date: ', LastImportDate)
print('Today date: ', Today)
print('Yesterday date: ', Yesterday)
def date_stamp(date):
return datetime.datetime.strptime(date,'%Y/%m/%d')
if date_stamp(LastImportDate) >= date_stamp(Yesterday):
print('No import operation')
else:
print('Start import operation')
=======
Output:
Last import date: 2019-01-11 23:00:00
Today date: 2020-06-15 06:28:49.492720
Yesterday date: 2020-06-14 06:28:49.492720
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-8-131b8da9ab87> in <module>
42 return datetime.datetime.strptime(date,'%Y/%m/%d')
43
---> 44 if date_stamp(LastImportDate) >= date_stamp(Yesterday):
45 print('No import operation')
46 else:
<ipython-input-8-131b8da9ab87> in unix_stamp(date)
40
41 def date_stamp(date):
---> 42 return datetime.datetime.strptime(date,'%Y/%m/%d')
43
44 if date_stamp(LastImportDate) >= date_stamp(Yesterday):
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
Aucun commentaire:
Enregistrer un commentaire