Select to view content in your preferred language

Date field attribute not displaying correctly

1563
11
04-25-2014 03:01 AM
H_A_D_Padmasiri
Deactivated User
Dear Sir
I entered date field as variable like VDate = Sys.argv[4] using arcpy.CalculateField_management("BLD_PG", "BLD_PG_DT", VDate, "PYTHON_9.3", "")
But in attribute table  attribute of the Date field look like 12:01:00 AM. How to correct it?

Thanks

Padmasiri
Tags (2)
0 Kudos
11 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Padmisiri,

You will want to format the date like the following:

time.strftime('05/02/2014')

Ex:

arcpy.CalculateField_management("BLD_PG", "BLD_PG_DT", "time.strftime('05/02/2014')", "PYTHON")
0 Kudos
H_A_D_Padmasiri
Deactivated User
Hi Padmisiri,

You will want to format the date like the following:

time.strftime('05/02/2014')

Ex:

arcpy.CalculateField_management("BLD_PG", "BLD_PG_DT", "time.strftime('05/02/2014')", "PYTHON")



Can you please explain How to enter '05/02/2014' as a variable. (VDate)

Thanks
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Here is an example:

VDate = "time.strftime('05/02/2014')"
0 Kudos
H_A_D_Padmasiri
Deactivated User
Here is an example:

VDate = "time.strftime('05/02/2014')"


Thank you for your answer.it runs correctly, But I add a field called "BLD_PG_DT"(Date Type) it gives me following error.
I cant understand the error. can you correct it.

Thanks

Padmasiri

VDate = sys.argv[4] # This date value from the calender
arcpy.AddField_management("BLD_PG", "BLD_PG_DT", "DATE", "", "", "", "Validity Date", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management("BLD_PG", "BLD_PG_DT", "time.strftime('VDate')", "PYTHON_9.3", "")

Traceback (most recent call last):
  File "J:\Gampaha\Scripts\Creating_Building.py", line 57, in <module>
    arcpy.CalculateField_management("BLD_PG", "BLD_PG_DT", "time.strftime('VDate')", "PYTHON_9.3", "")
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3128, in CalculateField
    raise e
ExecuteError: ERROR 999999: Error executing function.
The value type is incompatible with the field type. [BLD_PG_DT]
Failed to execute (CalculateField).


Failed to execute (LISTool1.02).
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Can you post your entire code?  Be sure to wrap it in the appropriate
 tags.
0 Kudos
H_A_D_Padmasiri
Deactivated User
Can you post your entire code?  Be sure to wrap it in the appropriate
 tags.


Dear sir

My entire code is send here with. Pl see attachment.

Thanks

Padmasiri
0 Kudos
JakeSkinner
Esri Esteemed Contributor
For some reason, I could not get this to work with 'sys.argv' but I was able to with arcpy.GetParameterAsText.  Are you able to use the GetParameterAsText rather than sys.argv?
0 Kudos
H_A_D_Padmasiri
Deactivated User
For some reason, I could not get this to work with 'sys.argv' but I was able to with arcpy.GetParameterAsText.  Are you able to use the GetParameterAsText rather than sys.argv?


Dear sir

When I save a date as a variyable, which I take from the calender like (mm/dd/yyyy).
My question is why that variyable directly enter to date field without formatting ?
What is the correct method to enter in to the date field which I take from the calender?
I cant understand what is the purpose of using calender.

Kindly explain me.

Thanks

Padmasiri
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Padmasiri,

Try replacing your sys.argv arguments with arcpy.GetParameterAsText.  Here is an example:

# Import arcpy module
import arcpy
import os
from arcpy import env
import shutil
import sys
import time

# Local variables:
Cad_File = arcpy.GetParameterAsText(1)#J:\Gampaha\510272\51027202.dwg
Pro_File = arcpy.GetParameterAsText(2)#I:\Projections\ProSriLanka99_5
Folder_Loca = arcpy.GetParameterAsText(3)#J:\Gampaha
VDate = "time.strftime('" + arcpy.GetParameterAsText(4) + "')"
Folder_Name = os.path.splitext(os.path.basename(Cad_File))[0]#51027202
Out_folder = os.path.join(Folder_Loca, Folder_Name)#J:\Gampaha\51027202
Gdb_Name = "CAD" + Folder_Name#CAD51027202
Gdb_Name1 = "CM" + Folder_Name#CM51027202
Gdb_Path = os.path.join(Out_folder, Gdb_Name)#J:\Gampaha\51027202\CAD51027202
Gdb_Path1 = os.path.join(Out_folder, Gdb_Name1)#J:\Gampaha\51027202\CM51027202
Fea_Dset_Name = "CAD" + Folder_Name#CAD51027202
Fea_Dset_Name1 = "CM" + Folder_Name#CAD51027202
Fea_Class_Path = os.path.join(Gdb_Path1 + ".gdb", Fea_Dset_Name1)#J:\Gampaha\51027202\CM51027202.gdb\CM51027202
if os.path.isdir(Out_folder):
    arcpy.env.workspace = Out_folder
    Gdb_List = arcpy.ListWorkspaces("", "FileGDB")
    for GDB in Gdb_List:
        arcpy.Delete_management(GDB)
    shutil.rmtree(Out_folder)
Ws_Path = Gdb_Path + ".gdb" + os.sep + Gdb_Name
arcpy.DefineProjection_management(Cad_File, Pro_File)
arcpy.CreateFolder_management(Folder_Loca, Folder_Name)#J:\Gampaha\510272\51027202
arcpy.env.workspace = Out_folder
arcpy.CreateFileGDB_management(Out_folder, Gdb_Name, "CURRENT")#J:\Gampaha\51027202\CAD51027202.gdb
arcpy.CreateFileGDB_management(Out_folder, Gdb_Name1, "CURRENT")#J:\Gampaha\51027202\CM51027202.gdb
arcpy.CreateFeatureDataset_management(Gdb_Path1 + ".gdb", Fea_Dset_Name1, Pro_File)#J:\Gampaha\51027202\CM51027202.gdb\CAD51027202
env.workspace = Gdb_Path + os.sep + Fea_Dset_Name
#arcpy.env.Scratchworkspace = Gdb_Path
arcpy.CADToGeodatabase_conversion(Cad_File, Gdb_Path + ".gdb", Fea_Dset_Name, "2000")
arcpy.CreateTopology_management(Fea_Class_Path, "PCL_LN_Topology", 0.01)
Polyline = Ws_Path + os.sep + "Polyline"
Pnt = Ws_Path + os.sep + "Point"
PLN_Topology = Fea_Class_Path + os.sep + "PCL_LN_Topology"
Fea_Class = Fea_Class_Path + os.sep + "BLD_LN" #NL
#Creating Structure Feature Class
env.workspace = Fea_Class_Path #NL
arcpy.FeatureClassToFeatureClass_conversion(Polyline, Fea_Class_Path, "BLD_LN", " \"Layer\" = 'OBJ-MAN-MADE' ")
arcpy.FeatureToPolygon_management(Fea_Class, Fea_Class_Path + os.sep + "BLD_PG", 0.01, "ATTRIBUTES", "")
arcpy.AddField_management("BLD_PG", "BLD_PG_NM", "TEXT", "", "", "50", "Building Name", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management("BLD_PG", "BLD_PG_CD", "SHORT", "", "", "", "BLD SD Code", "NULLABLE", "NON_REQUIRED", "")
SubType_Dict = {"0": "Permanent Building", "1": "Temporary Building", "2": "Building Underconstruction"}
arcpy.SetSubtypeField_management("BLD_PG", "BLD_PG_CD")
for code in SubType_Dict:
        arcpy.AddSubtype_management("BLD_PG", code, SubType_Dict
)
arcpy.SetDefaultSubtype_management("BLD_PG", "0")
arcpy.AddField_management("BLD_PG", "BLD_PG_DT", "DATE", "", "", "", "Validity Date", "NULLABLE", "NON_REQUIRED", "")
arcpy.CalculateField_management("BLD_PG", "BLD_PG_DT", VDate, "PYTHON_9.3", "")
0 Kudos