![]() |
reminder app logic problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: reminder app logic problem (/thread-42358.html) |
reminder app logic problem - jacksfrustration - Jun-24-2024 im making a reminder app. one of the first step would be to only accept dates set in the future and not in the past to avoid any user mistakes. Does anyone know how to do this? much appreciated RE: reminder app logic problem - menator01 - Jun-24-2024 Here is one way. from datetime import datetime present = datetime.now() past_date = '2015-10-25' obj = datetime.strptime(past_date, '%Y-%m-%d') answer = 'yes' if obj < present else 'no' print(f'Past -> {answer}') future_date = '2025-12-23' obj = datetime.strptime(future_date, '%Y-%m-%d') answer = 'yes' if obj < present else 'no' print(f'Future -> {answer}')Came from here RE: reminder app logic problem - jacksfrustration - Jun-24-2024 thanks a lot for your help mate.. much appreciated RE: reminder app logic problem - AdamHensley - Jul-01-2024 Hey, that sounds like an excellent idea for a reminder app! To ensure users can only set future dates, you can compare the selected date with the current date and time. You can show an error message if the selected date is earlier than the current date. In Python, you could use the datetime module to do this. |