Select to view content in your preferred language

Assign by Year in the field Calcuator using VB Script ?

1976
5
Jump to solution
09-21-2016 10:22 AM
PROBERT68
Honored Contributor

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

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
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
DarrenWiens2
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.
PROBERT68
Honored Contributor

Aww.. I see. Thanks !

0 Kudos
PROBERT68
Honored Contributor

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

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

0 Kudos
TedKowal
Honored Contributor

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

PROBERT68
Honored Contributor

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  !

0 Kudos