Question
Tata Consultancy Services
Tata Consultancy Services
IN
Tata Consultancy Services
Posted: Jun 21, 2017
Last activity: Jun 22, 2017
Last activity: 22 Jun 2017 5:19 EDT
Closed
Solved
Script not recognizing C# AddMonth funtion
Hi,
I'm trying to implement a script which accepts today's date and return the next months date but I'm getting invalid script error. Any help is appreciated.
Thanks
You are passing in a string and treating it as a DateTime. You need to change your input "thisDay" to a type of DateTime or cast it to a DateTime using DateTime.TryParse.
Assuming you pass it in as a string, the following will work;
DateTime dt;
if(DateTime.TryParse(thisDate, out dt))
{
return dt.AddMonths(1).ToString("dd-MMM-yyyy");
}
else
return string.Empty;