Using ArcGIS 10.4, how I can modify the Date()
functions on VB or Python scripts of field Calculator
Now ( )
datetime.datetime.now( )
to get only time like
12:32
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityUsing ArcGIS 10.4, how I can modify the Date()
functions on VB or Python scripts of field Calculator
Now ( )
datetime.datetime.now( )
to get only time like
12:32
This is a little off topic as it has to do with pure python (or VB).
Using the python parser you can get the current time with the function:
datetime.datetime.now().strftime('%H:%M') # use '%h:%M' for 12 hour time
Have a read of strftime behavior, note that this will be a string, not a datetime, so can only be stored in a string field.
The following python code can be run in a field calculate:
t = datetime.datetime.now()
h = t.hour
m = t.minute
s = str(h) + ":" + str(m)
You would then return the string s
which would be something "23:51".
You should also explore the tool Convert Time Field which already exists and can extract out a variety of formatted date/times. It is in the same toolbox as the Calculate Field tool...