Yes, I ended up splitting the date/time components like you mentioned Dan.
I found some interesting things with the Date data type:
- Even if you select date only radio button the parameter still 'holds' the time. It will be set to 00:00:00, but does not get passed onto your arcpy script though.
- If you select Time only, the date is still stored in the parameter. It is set to 1899-12-30. But it too will not be passed onto your arpcy script.
- If you program in the validation code to strip out the time, the radio button changes automatically.
I found those funny things with the date/time because I wanted to send an error if a Time type was entered. The validation always returned true when looking for time, even when there was only a date in my parameter.
Below is how I went about striping out the time and keeping only the date. I am using this tool with different date formats which is why you see a reference to a dictionary. And the second chunk of code shows how I use this function in the Update Messages potion of the validation.
def checkIfTimeOnly(self, winDate, theDate):
dateEdit = str(theDate)
dateSplit = dateEdit.split()
dateDate = dateSplit[0]
zeroDate = datetime.strptime("1899-12-30", "%Y-%m-%d").date()
dateForm = datetime.strptime(str(dateDate), date_dictionary[winDate]).date()
if dateForm == zeroDate:
return True
else:
return False
if self.params[7].altered:
if self.params[7].value:
isTime = self.checkIfTimeOnly(winDateValue, self.params[7].value)
if isTime:
self.params[7].setErrorMessage("Is not a date")
if self.params[8].value == None:
self.params[8].value = self.params[7].value
if self.params[8].altered:
if self.params[8].value:
isTime = self.checkIfTimeOnly(winDateValue, self.params[8].value)
if isTime:
self.params[8].setErrorMessage("Is not a date")
if self.params[7].value and self.params[8].value:
if self.params[7].value > self.params[8].value:
self.params[8].setErrorMessage("End date must be later than Start Date.")
Cheers,
Natasha