Assign by Year in the field Calcuator using VB Script ?

998
5
Jump to solution
09-21-2016 10:22 AM
Highlighted
Regular Contributor II

As I am working on several shapefiles that needed to be populate Date in the field column. How do you do assign VBscript in the field calculator to assign for one year  for 2010 or 2016  or 2014 ?

Seems every time I tried to follow what ESRI field calculator I get failed ?

like this : Date ( "2016" ) returns failed !

If you have a better suggest or work around, I can do either VB Script or Python.

Thanks

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Honored Contributor

I assume you're trying to calculate this into a date datatype field? I believe you need to supply a day, month, and year to fit the format.

Fundamentals of date fields—Help | ArcGIS for Desktop 

A coverage or shapefile stores dates in a date field with this format: yyyy-mm-dd. A geodatabase formats the date as datetime yyyy-mm-dd hh:mm:ss AM or PM.

View solution in original post

5 Replies
Highlighted
MVP Honored Contributor

I assume you're trying to calculate this into a date datatype field? I believe you need to supply a day, month, and year to fit the format.

Fundamentals of date fields—Help | ArcGIS for Desktop 

A coverage or shapefile stores dates in a date field with this format: yyyy-mm-dd. A geodatabase formats the date as datetime yyyy-mm-dd hh:mm:ss AM or PM.

View solution in original post

Highlighted
Regular Contributor II

Aww.. I see. Thanks !

Reply
0 Kudos
Highlighted
Regular Contributor II

I also found this https://community.esri.com/thread/16945 

and look at what Marcus Perrine  wrote. That one worked too..

Reply
0 Kudos
Highlighted
Regular Contributor II

If your required context is for a year only why not use a integer field instead of a date field?  However, if you want to assign a Year only within a date field, then you would have to chose a default value for your Month and day as Darren Wiens  link indicates.

If changing your date field to an integer is not an option you can use the the following script and substitute your own default month/day....

CDATE("1/1/2016")

Note in vbscript if memory serves right Date() returns the system date......

Highlighted
Regular Contributor II

Thank you. The reason is that I am asking is because I have the geodatabase that was already done by somebody else and use the template that I cannot change. 

Thanks for the suggest  !

Reply
0 Kudos