I am currently using an event receiver in a SharePoint site meant to onboard new employees. New user info is entered into a list called "New Hire Profile" and a second list called "Access Profile" is created based on the new hire profile list. There is a field on the employee profile called "Start Date" which is a simple SharePoint date content type. I am trying to create an calculated "Due Date" field in the access profile for tasks due on the start date. I would like to add the "StartDate" which is a date picker and "Dueindays" which is a numeric field listed on a third list "newHireTaskTemplate". The code is setup to pull the info from the fields and copy them to the new list. I am unsure how to go about adding days to the date picker date. My code currently looks like this:

accessProfile["Title"] = employeeProfile.ContentType.Name;
accessProfile["FirstName"] = employeeProfile["FirstName"];
accessProfile["LastName"] = employeeProfile["LastName"];
accessProfile["StartDate"] = employeeProfile["StartDate"];
accessProfile["DueDate"] = employeeProfile["StartDate"] + newHireTaskTemplate[DueinDays]???

1 Answer 1


Please check the below Sample:

DateTime date = Convert.ToDateTime(employeeProfile["StartDate"].ToString());
int days=Convert.ToInt32(newHireTaskTemplate[DueinDays].ToString());

accessProfile["DueDate"] = date ;
  • Thank you for replying. I assume the first line is missing an ")" code string date = Convert.ToDateTime(employeeProfile["StartDate"].ToString());code I get error: Cannot implicitly convert type 'string' to 'System.DateTime'
    – initech
    Commented Jul 17, 2018 at 18:32
  • I have since tried code string date = Convert.ToDateTime(employeeProfile["StartDate"]).ToString();code which it seems to like. However in code date.AddDays(days); code it does not like .AddDays. I get "Error String does not contain a definition for "AddDays" and no extension method adddays accepting a first argument of type 'string' could be found.
    – initech
    Commented Jul 17, 2018 at 18:59
  • @initech yes you're right i wrote it right a way without IDE and didn't review it's my mistake, check the update
    – A.Saéed
    Commented Jul 17, 2018 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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