Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
99 views
in Technique[技术] by (71.8m points)

python - Substracting dates in PyMongo

I am designing an application by using MongoDB and Tkinter. I am taking inputs from user and send them to the database. Main goal of the application is showing customers who are due for maintenance in a new window. Maintenances will be held once a year.

To do that I have a database field named mainenanceDate. This field holds next maintenance day of clients. I planned substracting maintenanceDate from currentDate and if the result smaller or equal than 0. This entity will be shown in a new window.

That is how I take inputs from user. I used dateutil because MongoDB was holding maintenanceDate as string.

def inputFunc():
    def addClientFunc():
        database.Clients.insert_one({
            "c_id": idEntry.get(),
            "c_name": nameEntry.get(),
            "c_firmName": firmNameEntry.get(),
            "address": addressEntry.get(),
            "engine": engineEntry.get(),
            "power": powerEntry.get(),
            "phoneNumber": phoneNumberEntry.get(),
            "email": emailEntry.get(),
            "workHour": workHourEntry.get(),
            "maintenanceDate": dateutil.parser.parse(maintenanceEntry.get())
    }) 

The problem is i'm not able to substract dates from each other because PyMongo doesn't allow me to reach maintenanceDate column. How can I reach that column? If you have any other suggestions or another way to do that please feel free to write them.

That is the code I have tried.

for row in database.Clients.find({},{'_id': 0}):
        delta = maintenanceDate - datetime.datetime.now()
        if(delta <= 0):
            row
            tree.insert("", END, values=[x for x in row.values()])
question from:https://stackoverflow.com/questions/66053532/substracting-dates-in-pymongo

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...