2

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

  • datetime.datetime.now() should return a datetime object with the date and time.. are you trying to store this in a date field or a string field? What do you get if you calc to datetime.datetime.now().date()? – Michael Stimson Sep 26 '17 at 22:48
4

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.

2

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.