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

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Sep 26, 2017 at 22:36
1
  • 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()? Commented Sep 26, 2017 at 22:48

2 Answers 2

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.

answered Sep 26, 2017 at 22:59
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...

answered Sep 26, 2017 at 22:58

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.