I have developed a Python script using ArcPy with one of the output variable being of Date type. In the actual Python code, the variable is a Python datetime object which has both the date and time sections.

A snippet of Python script "ExtractNetCDFToRaster.py" is as below. The purpose of the code is to extract a raster layer out of a netCDF file with the raster and the date and time (in the "time" dimension) as output.

import sys, os
from os.path import basename
import arcpy
import datetime
from dateutil import tz

# Convert UTC datetime to local datetime
def convertToLocalDT(string):
    from_zone = tz.tzutc()
    to_zone = tz.tzlocal()

    # 20/11/2017 1:00:00 PM
    dtUTC = datetime.datetime.strptime(string, "%d/%m/%Y %I:%M:%S %p")
    dtLocal = dtUTC.replace(tzinfo=from_zone).astimezone(to_zone)

    return dtLocal

# get dimension values from the time dimension
dimension_values = nc_FP.getDimensionValue("time", 0)

# the dimension_values is of a unicode type of data, e.g. u'20/11/2017 1:00:00 PM'
strDimensionValues = dimension_values.encode('utf-8')
arcpy.AddMessage("dimension_values: " + strDimensionValues)
dtDimensionValues = convertToLocalDT(strDimensionValues)


# Set dtDimensionValues as output which has an alias of "outDateTime" in the tool Properties window.
arcpy.SetParameter(5, dtDimensionValues)

enter image description here

When I imported this script into a Model as a custom tool and ran the tool, the variable only output the date but not the time section. For example, if the actual datetime is "2017-11-21 00:00:00" the outDateTime only shows "21/11/2017". enter image description here

closed as off-topic by PolyGeo Nov 20 '17 at 6:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.


Is it being written into an attribute field of a shapefile as date type? it could be that the date time is not being recognised because of the way it is going in. It will be truncated if that is the case.

From Help

Some of the functions support datetime yyyy-mm-dd hh:mm:ss AM or PM. However, for coverages and shapefiles, the time portion is truncated from the datetime value. For example, the datetime 2002-08-20 12:00:00 PM is stored in a coverage or shapefile as 2002-08-20.

  • No the date output is just a variable in Date type in the custom tool written in Python. When used in a Model, it is output as Date not including Time. – alextc Nov 20 '17 at 5:59
  • 1
    So what is it actually being used in? Would probably help if you posted your script to help troubleshoot the problem. – Daniel Mccullock Nov 20 '17 at 6:17
  • Please view the updated question with code added. – alextc Nov 20 '17 at 23:51
  • 1
    Have you tried using SetParameterAsText instead of SetParameter? You can calculate a date field value using text so I would assume this would work the same for the Date parameter type. – Daniel Mccullock Nov 21 '17 at 1:10

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