public static SPField EnsureField(this SPList list, SPFieldType type, string displayName, string internalName, bool isRequired, SPCalendarType calendarType)
        {
            var field = list.EnsureField(type, displayName, internalName, isRequired);

            if (field.Type == SPFieldType.DateTime)
            {
                try
                {
                    if (!list.Fields.ContainsField(internalName))
                    {
                        list.Fields.Add(internalName, SPFieldType.DateTime, false);
                        list.Update();

                        (field as SPFieldDateTime).DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
                        (field as SPFieldDateTime).CalendarType  = calendarType;
                        field.Update();
                    }
                    else
                    {
                        (field as SPFieldDateTime).DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
                        (field as SPFieldDateTime).CalendarType  = calendarType;
                        field.Update();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex);
                }
            }
            return(field);
        }
        public static SPField EnsureField(this SPList list, SPFieldType type, string displayName, string internalName, bool isRequired, string formula)
        {
            var field = list.EnsureField(type, displayName, internalName, isRequired);

            if (field.Type == SPFieldType.Calculated)
            {
                var strNewField = (SPFieldCalculated)field;
                strNewField.Formula = formula;
                strNewField.Update();
            }

            return(field);
        }