I am accessing date from database using below query, in my jupyterLab notebook:
newDate = con.cursor() newDate.execute("select max(CalendarDate) as cdates from db.table1 where cdates < getdate()") c_date = newDate.fetchone() cDate = str(c_date) current_date = datetime.strptime(cDate,'%Y/%m/%d').strftime('%m/%d/%Y') print(currentdate)
it is giving this ValueError: time data ‘(datetime.date(2021, 7, 30), )’ does not match format ‘%Y/%m/%d’
can anyone guide, the correct way pls?
Advertisement
Answer
Seems like c_date
is already a datetime.date object. You don’t need to cDate = str(c_date)
.
try:
newDate = con.cursor() newDate.execute("select max(CalendarDate) as cdates from db.table1 where cdates < getdate()") c_date = newDate.fetchval() current_date = c_date.strftime('%m/%d/%Y') print(currentdate)