Classifying time periods in new field using Python Parser of ArcGIS Desktop?Using python elif syntax in Field...

How do I check if a string is entirely made of the same substring?

What does ゆーか mean?

Is there really no use for MD5 anymore?

Is there any official lore on the Far Realm?

What's the name of these pliers?

As an international instructor, should I openly talk about my accent?

Why was the Spitfire's elliptical wing almost uncopied by other aircraft of World War 2?

Don’t seats that recline flat defeat the purpose of having seatbelts?

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

How do I reattach a shelf to the wall when it ripped out of the wall?

infinitely many negative and infinitely many positive numbers

How to have a sharp product image?

How to denote matrix elements succinctly?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

What happened to Captain America in Endgame?

On The Origin of Dissonant Chords

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

What are the characteristics of a typeless programming language?

Extension of 2-adic valuation to the real numbers

Classification of surfaces

"You've called the wrong number" or "You called the wrong number"

How can I practically buy stocks?

If a planet has 3 moons, is it possible to have triple Full/New Moons at once?

Minor Revision with suggestion of an alternative proof by reviewer



Classifying time periods in new field using Python Parser of ArcGIS Desktop?


Using python elif syntax in Field Calculator to reclassify a range of values from a different field and populate a new fieldCalculate Date field in ArcPyConverting values in datetime field to strings in text field using Python parser of ArcGIS for Desktop?Converting Date field to string using ArcGIS for Desktop?If/Then Field Calculator Return CalculationsCalculating field with hour from date time field with ArcPy?Python Max Function in Field Calculator for Date valuesArcGIS field calculator to calculate most recent date of 4 date fields?Getting only time from Python parser of ArcGIS Field Calculator?Using Python to convert string values with Calculate Field in ArcGIS ModelBuilder?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







6















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?



that's how my table looks like










share|improve this question

























  • what is the type of field for horario / actual values in your attributes?

    – GISKid
    Jul 18 '14 at 13:05











  • The type is date, the actual values are shown like 09:10:00, for instance, but when I do a SQL Query, it appears as date '1899-12-30 09:10:00'. I think that's why I'm getting confuse, I don't know how the actual values are being stored.

    – Beatriz Viseu
    Jul 18 '14 at 13:08






  • 1





    Well, AND is not a valid python keyword, so you'll always get an invalid syntax error.

    – Paul
    Jul 18 '14 at 13:12











  • Omg, I can't believe I missed that! Thanks so much Paul! Unfortunately, that was not the only problem, I'm still getting a sintax error...

    – Beatriz Viseu
    Jul 18 '14 at 13:17


















6















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?



that's how my table looks like










share|improve this question

























  • what is the type of field for horario / actual values in your attributes?

    – GISKid
    Jul 18 '14 at 13:05











  • The type is date, the actual values are shown like 09:10:00, for instance, but when I do a SQL Query, it appears as date '1899-12-30 09:10:00'. I think that's why I'm getting confuse, I don't know how the actual values are being stored.

    – Beatriz Viseu
    Jul 18 '14 at 13:08






  • 1





    Well, AND is not a valid python keyword, so you'll always get an invalid syntax error.

    – Paul
    Jul 18 '14 at 13:12











  • Omg, I can't believe I missed that! Thanks so much Paul! Unfortunately, that was not the only problem, I'm still getting a sintax error...

    – Beatriz Viseu
    Jul 18 '14 at 13:17














6












6








6








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?



that's how my table looks like










share|improve this question
















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?



that's how my table looks like







arcgis-desktop field-calculator python-parser datetime if-else






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 27 mins ago









PolyGeo

54.1k1782247




54.1k1782247










asked Jul 18 '14 at 13:03









Beatriz ViseuBeatriz Viseu

1216




1216













  • what is the type of field for horario / actual values in your attributes?

    – GISKid
    Jul 18 '14 at 13:05











  • The type is date, the actual values are shown like 09:10:00, for instance, but when I do a SQL Query, it appears as date '1899-12-30 09:10:00'. I think that's why I'm getting confuse, I don't know how the actual values are being stored.

    – Beatriz Viseu
    Jul 18 '14 at 13:08






  • 1





    Well, AND is not a valid python keyword, so you'll always get an invalid syntax error.

    – Paul
    Jul 18 '14 at 13:12











  • Omg, I can't believe I missed that! Thanks so much Paul! Unfortunately, that was not the only problem, I'm still getting a sintax error...

    – Beatriz Viseu
    Jul 18 '14 at 13:17



















  • what is the type of field for horario / actual values in your attributes?

    – GISKid
    Jul 18 '14 at 13:05











  • The type is date, the actual values are shown like 09:10:00, for instance, but when I do a SQL Query, it appears as date '1899-12-30 09:10:00'. I think that's why I'm getting confuse, I don't know how the actual values are being stored.

    – Beatriz Viseu
    Jul 18 '14 at 13:08






  • 1





    Well, AND is not a valid python keyword, so you'll always get an invalid syntax error.

    – Paul
    Jul 18 '14 at 13:12











  • Omg, I can't believe I missed that! Thanks so much Paul! Unfortunately, that was not the only problem, I'm still getting a sintax error...

    – Beatriz Viseu
    Jul 18 '14 at 13:17

















what is the type of field for horario / actual values in your attributes?

– GISKid
Jul 18 '14 at 13:05





what is the type of field for horario / actual values in your attributes?

– GISKid
Jul 18 '14 at 13:05













The type is date, the actual values are shown like 09:10:00, for instance, but when I do a SQL Query, it appears as date '1899-12-30 09:10:00'. I think that's why I'm getting confuse, I don't know how the actual values are being stored.

– Beatriz Viseu
Jul 18 '14 at 13:08





The type is date, the actual values are shown like 09:10:00, for instance, but when I do a SQL Query, it appears as date '1899-12-30 09:10:00'. I think that's why I'm getting confuse, I don't know how the actual values are being stored.

– Beatriz Viseu
Jul 18 '14 at 13:08




1




1





Well, AND is not a valid python keyword, so you'll always get an invalid syntax error.

– Paul
Jul 18 '14 at 13:12





Well, AND is not a valid python keyword, so you'll always get an invalid syntax error.

– Paul
Jul 18 '14 at 13:12













Omg, I can't believe I missed that! Thanks so much Paul! Unfortunately, that was not the only problem, I'm still getting a sintax error...

– Beatriz Viseu
Jul 18 '14 at 13:17





Omg, I can't believe I missed that! Thanks so much Paul! Unfortunately, that was not the only problem, I'm still getting a sintax error...

– Beatriz Viseu
Jul 18 '14 at 13:17










1 Answer
1






active

oldest

votes


















5














Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field:



with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0])




2014-07-18 06:03:05 <type 'datetime.datetime'>
2014-07-17 00:00:00 <type 'datetime.datetime'>


So, the easiest way to build this would be with the datetime module.



from datetime import datetime as dt    
test = dt(2014, 7, 18, 6, 3, 5)

with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0]), row[0] == test




2014-07-18 06:03:05 <type 'datetime.datetime'> True
2014-07-17 00:00:00 <type 'datetime.datetime'> False


Instead of using and, there is a simpler way to check if a number lies between two numbers see here I believe the following is correct:



def Reclass(horario):

if dt(1899,12,30, 12,0,0) > horario >= dt(1899,12,30, 6,0,0):
return "Manhã (6-12h)"

elif dt(1899,12,30, 18,0,0) > horario >= dt(1899,12,30, 12,0,0):
return "Tarde (12-18h)"

elif dt(1899,12,30, 23,59,0) >= horario >= dt(1899,12,30, 18,0,0):
return "Noite (18-24h)"

elif dt(1899,12,30, 6,0,0) > horario >= dt(1899,12,30, 0,0,0):
return "Madrugada (0-6h)"





share|improve this answer


























  • That makes a lot of sense, Paul! Thanks for the throughout answer! It's really helping me understand how to use date with python. I used the code as shown, but I get the error File "<expression>", line 1, in <module> File "<string>", line 4, in Reclass TypeError: can't compare datetime.datetime to unicode It's weird, because the only string I have it's after return. Any guess?

    – Beatriz Viseu
    Jul 18 '14 at 14:30











  • @Beatriz Viseu, horario is in unicode, likely.

    – Paul
    Jul 18 '14 at 14:34













  • Yeah, so I changed my code to the '1899-12-30 06:00:00' style, and it's now comparable. It even worked with a simpler code (if horario > '1899-12-30 06:00:00': return "Manhã"). However, it doesn't seem to like when I use multiple statements (horario>x and horario<y / x>horario>y). I tried both ways, the tool does run, I don't get any error, but all my records keep as <Null>. I have no idea what's wrong.

    – Beatriz Viseu
    Jul 21 '14 at 16:16











  • @BeatrizViseu, So you aren't using the datetime module at all? You might want to update your question with the new code or start another one if you have a different question entirely.

    – Paul
    Jul 21 '14 at 16:23












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f107659%2fclassifying-time-periods-in-new-field-using-python-parser-of-arcgis-desktop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field:



with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0])




2014-07-18 06:03:05 <type 'datetime.datetime'>
2014-07-17 00:00:00 <type 'datetime.datetime'>


So, the easiest way to build this would be with the datetime module.



from datetime import datetime as dt    
test = dt(2014, 7, 18, 6, 3, 5)

with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0]), row[0] == test




2014-07-18 06:03:05 <type 'datetime.datetime'> True
2014-07-17 00:00:00 <type 'datetime.datetime'> False


Instead of using and, there is a simpler way to check if a number lies between two numbers see here I believe the following is correct:



def Reclass(horario):

if dt(1899,12,30, 12,0,0) > horario >= dt(1899,12,30, 6,0,0):
return "Manhã (6-12h)"

elif dt(1899,12,30, 18,0,0) > horario >= dt(1899,12,30, 12,0,0):
return "Tarde (12-18h)"

elif dt(1899,12,30, 23,59,0) >= horario >= dt(1899,12,30, 18,0,0):
return "Noite (18-24h)"

elif dt(1899,12,30, 6,0,0) > horario >= dt(1899,12,30, 0,0,0):
return "Madrugada (0-6h)"





share|improve this answer


























  • That makes a lot of sense, Paul! Thanks for the throughout answer! It's really helping me understand how to use date with python. I used the code as shown, but I get the error File "<expression>", line 1, in <module> File "<string>", line 4, in Reclass TypeError: can't compare datetime.datetime to unicode It's weird, because the only string I have it's after return. Any guess?

    – Beatriz Viseu
    Jul 18 '14 at 14:30











  • @Beatriz Viseu, horario is in unicode, likely.

    – Paul
    Jul 18 '14 at 14:34













  • Yeah, so I changed my code to the '1899-12-30 06:00:00' style, and it's now comparable. It even worked with a simpler code (if horario > '1899-12-30 06:00:00': return "Manhã"). However, it doesn't seem to like when I use multiple statements (horario>x and horario<y / x>horario>y). I tried both ways, the tool does run, I don't get any error, but all my records keep as <Null>. I have no idea what's wrong.

    – Beatriz Viseu
    Jul 21 '14 at 16:16











  • @BeatrizViseu, So you aren't using the datetime module at all? You might want to update your question with the new code or start another one if you have a different question entirely.

    – Paul
    Jul 21 '14 at 16:23
















5














Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field:



with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0])




2014-07-18 06:03:05 <type 'datetime.datetime'>
2014-07-17 00:00:00 <type 'datetime.datetime'>


So, the easiest way to build this would be with the datetime module.



from datetime import datetime as dt    
test = dt(2014, 7, 18, 6, 3, 5)

with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0]), row[0] == test




2014-07-18 06:03:05 <type 'datetime.datetime'> True
2014-07-17 00:00:00 <type 'datetime.datetime'> False


Instead of using and, there is a simpler way to check if a number lies between two numbers see here I believe the following is correct:



def Reclass(horario):

if dt(1899,12,30, 12,0,0) > horario >= dt(1899,12,30, 6,0,0):
return "Manhã (6-12h)"

elif dt(1899,12,30, 18,0,0) > horario >= dt(1899,12,30, 12,0,0):
return "Tarde (12-18h)"

elif dt(1899,12,30, 23,59,0) >= horario >= dt(1899,12,30, 18,0,0):
return "Noite (18-24h)"

elif dt(1899,12,30, 6,0,0) > horario >= dt(1899,12,30, 0,0,0):
return "Madrugada (0-6h)"





share|improve this answer


























  • That makes a lot of sense, Paul! Thanks for the throughout answer! It's really helping me understand how to use date with python. I used the code as shown, but I get the error File "<expression>", line 1, in <module> File "<string>", line 4, in Reclass TypeError: can't compare datetime.datetime to unicode It's weird, because the only string I have it's after return. Any guess?

    – Beatriz Viseu
    Jul 18 '14 at 14:30











  • @Beatriz Viseu, horario is in unicode, likely.

    – Paul
    Jul 18 '14 at 14:34













  • Yeah, so I changed my code to the '1899-12-30 06:00:00' style, and it's now comparable. It even worked with a simpler code (if horario > '1899-12-30 06:00:00': return "Manhã"). However, it doesn't seem to like when I use multiple statements (horario>x and horario<y / x>horario>y). I tried both ways, the tool does run, I don't get any error, but all my records keep as <Null>. I have no idea what's wrong.

    – Beatriz Viseu
    Jul 21 '14 at 16:16











  • @BeatrizViseu, So you aren't using the datetime module at all? You might want to update your question with the new code or start another one if you have a different question entirely.

    – Paul
    Jul 21 '14 at 16:23














5












5








5







Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field:



with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0])




2014-07-18 06:03:05 <type 'datetime.datetime'>
2014-07-17 00:00:00 <type 'datetime.datetime'>


So, the easiest way to build this would be with the datetime module.



from datetime import datetime as dt    
test = dt(2014, 7, 18, 6, 3, 5)

with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0]), row[0] == test




2014-07-18 06:03:05 <type 'datetime.datetime'> True
2014-07-17 00:00:00 <type 'datetime.datetime'> False


Instead of using and, there is a simpler way to check if a number lies between two numbers see here I believe the following is correct:



def Reclass(horario):

if dt(1899,12,30, 12,0,0) > horario >= dt(1899,12,30, 6,0,0):
return "Manhã (6-12h)"

elif dt(1899,12,30, 18,0,0) > horario >= dt(1899,12,30, 12,0,0):
return "Tarde (12-18h)"

elif dt(1899,12,30, 23,59,0) >= horario >= dt(1899,12,30, 18,0,0):
return "Noite (18-24h)"

elif dt(1899,12,30, 6,0,0) > horario >= dt(1899,12,30, 0,0,0):
return "Madrugada (0-6h)"





share|improve this answer















Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field:



with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0])




2014-07-18 06:03:05 <type 'datetime.datetime'>
2014-07-17 00:00:00 <type 'datetime.datetime'>


So, the easiest way to build this would be with the datetime module.



from datetime import datetime as dt    
test = dt(2014, 7, 18, 6, 3, 5)

with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor:
for row in cursor:
print row[0], type(row[0]), row[0] == test




2014-07-18 06:03:05 <type 'datetime.datetime'> True
2014-07-17 00:00:00 <type 'datetime.datetime'> False


Instead of using and, there is a simpler way to check if a number lies between two numbers see here I believe the following is correct:



def Reclass(horario):

if dt(1899,12,30, 12,0,0) > horario >= dt(1899,12,30, 6,0,0):
return "Manhã (6-12h)"

elif dt(1899,12,30, 18,0,0) > horario >= dt(1899,12,30, 12,0,0):
return "Tarde (12-18h)"

elif dt(1899,12,30, 23,59,0) >= horario >= dt(1899,12,30, 18,0,0):
return "Noite (18-24h)"

elif dt(1899,12,30, 6,0,0) > horario >= dt(1899,12,30, 0,0,0):
return "Madrugada (0-6h)"






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 18 '14 at 13:40

























answered Jul 18 '14 at 13:22









PaulPaul

11.1k12241




11.1k12241













  • That makes a lot of sense, Paul! Thanks for the throughout answer! It's really helping me understand how to use date with python. I used the code as shown, but I get the error File "<expression>", line 1, in <module> File "<string>", line 4, in Reclass TypeError: can't compare datetime.datetime to unicode It's weird, because the only string I have it's after return. Any guess?

    – Beatriz Viseu
    Jul 18 '14 at 14:30











  • @Beatriz Viseu, horario is in unicode, likely.

    – Paul
    Jul 18 '14 at 14:34













  • Yeah, so I changed my code to the '1899-12-30 06:00:00' style, and it's now comparable. It even worked with a simpler code (if horario > '1899-12-30 06:00:00': return "Manhã"). However, it doesn't seem to like when I use multiple statements (horario>x and horario<y / x>horario>y). I tried both ways, the tool does run, I don't get any error, but all my records keep as <Null>. I have no idea what's wrong.

    – Beatriz Viseu
    Jul 21 '14 at 16:16











  • @BeatrizViseu, So you aren't using the datetime module at all? You might want to update your question with the new code or start another one if you have a different question entirely.

    – Paul
    Jul 21 '14 at 16:23



















  • That makes a lot of sense, Paul! Thanks for the throughout answer! It's really helping me understand how to use date with python. I used the code as shown, but I get the error File "<expression>", line 1, in <module> File "<string>", line 4, in Reclass TypeError: can't compare datetime.datetime to unicode It's weird, because the only string I have it's after return. Any guess?

    – Beatriz Viseu
    Jul 18 '14 at 14:30











  • @Beatriz Viseu, horario is in unicode, likely.

    – Paul
    Jul 18 '14 at 14:34













  • Yeah, so I changed my code to the '1899-12-30 06:00:00' style, and it's now comparable. It even worked with a simpler code (if horario > '1899-12-30 06:00:00': return "Manhã"). However, it doesn't seem to like when I use multiple statements (horario>x and horario<y / x>horario>y). I tried both ways, the tool does run, I don't get any error, but all my records keep as <Null>. I have no idea what's wrong.

    – Beatriz Viseu
    Jul 21 '14 at 16:16











  • @BeatrizViseu, So you aren't using the datetime module at all? You might want to update your question with the new code or start another one if you have a different question entirely.

    – Paul
    Jul 21 '14 at 16:23

















That makes a lot of sense, Paul! Thanks for the throughout answer! It's really helping me understand how to use date with python. I used the code as shown, but I get the error File "<expression>", line 1, in <module> File "<string>", line 4, in Reclass TypeError: can't compare datetime.datetime to unicode It's weird, because the only string I have it's after return. Any guess?

– Beatriz Viseu
Jul 18 '14 at 14:30





That makes a lot of sense, Paul! Thanks for the throughout answer! It's really helping me understand how to use date with python. I used the code as shown, but I get the error File "<expression>", line 1, in <module> File "<string>", line 4, in Reclass TypeError: can't compare datetime.datetime to unicode It's weird, because the only string I have it's after return. Any guess?

– Beatriz Viseu
Jul 18 '14 at 14:30













@Beatriz Viseu, horario is in unicode, likely.

– Paul
Jul 18 '14 at 14:34







@Beatriz Viseu, horario is in unicode, likely.

– Paul
Jul 18 '14 at 14:34















Yeah, so I changed my code to the '1899-12-30 06:00:00' style, and it's now comparable. It even worked with a simpler code (if horario > '1899-12-30 06:00:00': return "Manhã"). However, it doesn't seem to like when I use multiple statements (horario>x and horario<y / x>horario>y). I tried both ways, the tool does run, I don't get any error, but all my records keep as <Null>. I have no idea what's wrong.

– Beatriz Viseu
Jul 21 '14 at 16:16





Yeah, so I changed my code to the '1899-12-30 06:00:00' style, and it's now comparable. It even worked with a simpler code (if horario > '1899-12-30 06:00:00': return "Manhã"). However, it doesn't seem to like when I use multiple statements (horario>x and horario<y / x>horario>y). I tried both ways, the tool does run, I don't get any error, but all my records keep as <Null>. I have no idea what's wrong.

– Beatriz Viseu
Jul 21 '14 at 16:16













@BeatrizViseu, So you aren't using the datetime module at all? You might want to update your question with the new code or start another one if you have a different question entirely.

– Paul
Jul 21 '14 at 16:23





@BeatrizViseu, So you aren't using the datetime module at all? You might want to update your question with the new code or start another one if you have a different question entirely.

– Paul
Jul 21 '14 at 16:23


















draft saved

draft discarded




















































Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f107659%2fclassifying-time-periods-in-new-field-using-python-parser-of-arcgis-desktop%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Щит и меч (фильм) Содержание Названия серий | Сюжет |...

is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

Meter-Bus Содержание Параметры шины | Стандартизация |...