I am currently developing an application in which a user fills out forms to submit upcoming activities (which will later be automatically scheduled, haven't got to that yet). So far I have been using the standard datetime
module for validation on form inputs to check that valid datetimes are being inputed, for example:
import datetime
import tkinter as tk
from tkinter import messagebox as tkMessageBox
#Loads of tkinter stuff leading to variables year, month, day, hour, minute
try:
start_date_time = datetime.datetime(year,month,day,hour,minute)
except ValueError as inst:
tkMessageBox.showerror("Invalid input",inst)
This has been very successful. My problem now is that I want to validate that start_date_time
is in the future. I was hoping that I would be able to do this by manipulating datetime.datetime.min
and datetime.datetime.max
in order to make the existing code validate to see if an input is in the future (and not unreasonably far in the future, too).
This is how I have tried to achieve this:
now = datetime.datetime.now()
datetime.datetime.min = now
But this raises the following TypeError
:
Traceback (most recent call last):
File "J:\COMP4 Project\GUI.py", line 13, in <module>
datetime.datetime.min = now
TypeError: can't set attributes of built-in/extension type 'datetime.datetime'
My question is: Is there a work around so that the values of datetime.datetime.min
and datetime.datetime.max
can be changed or must I write code to check each datetime to be validated is greater than now
?