Reputation: 177
I am using a PyQt5 GUI application and I need to get the value of yesterdays from any date in the QdateEdite I have inside the GUI application, for example I want to choose the day I use this code
date_n = str(self.dateEdit_2.text())
How can I get the ysterday of the day_n whenever the date_n it will be?
Upvotes: 1
Views: 442
Reputation: 243993
You have to get the QDate from QDateEdit, then subtract one day from it and then convert it to a string:
selected_dt = self.dateEdit_2.date()
last_dt = selected_dt.addDays(-1)
last_dt_str = last_dt.toString(self.dateEdit_2.displayFormat())
print(last_dt_str)
Upvotes: 2