I have a datetime field (Horario) in my feature class, showing only the time. Although the date doesn't appear, it seem to be stored automatically as 30 Dec 1899, I'm not sure why.
I want to use this field to populate another field (Periodo) , where I'll have different periods of the day: morning (6 am - 12pm), afternoon (12pm - 6pm), evening (6pm - 12am) and night (12am - 6am).
I'm trying to write an if-elif statement on the Field Calculator, but I'm always having an "invalid syntax" error, and I'm guessing that's because of the datetime expression I'm using. Can anyone see what's wrong?
def Reclass(horario): if (horario < date '1899-12-30 12:00:00' and horario >= date '1899-12-30 06:00:00'): return "Manhã (6-12h)" elif (horario < date '1899-12-30 18:00:00' and horario >= date '1899-12-30 12:00:00'): return "Tarde (12-18h)" elif (horario <= date '1899-12-30 23:59:00' and horario >= date '1899-12-30 18:00:00'): return "Noite (18-24h)" elif (horario < date '1899-12-30 06:00:00' and horario >= date '1899-12-30 00:00:00'): return "Madrugada (0-6h)" Reclass(!Horário!)
I'm thinking the problem is I'm referring to the date as
date '1899-12-30 06:00:00'
How should I refer to datetime fields when using Python?