I was looking all over the internet for this functionality but couldn't find any acceptable solution Simple question, How can you add 1.5 month to a DateTime, AddMonth accepts only integer as a parameter. and yes i know i can use AddDays, but it brings many other questions of how to calculate proper number of days depends on a moths you are looking at
my own solution is bellow, but for sure it is not the perfect one
public static DateTime AddMonths(DateTime val, double months)
{
int integer =(int) Math.Truncate(months);
double fraction = months - integer;
val = val.AddMonths(integer);
double days = DateTime.DaysInMonth(val.Year, val.Month) * fraction;
val = val.AddDays(days);
return val;
}
Update: This is a business project requirements. One of the forms has Issue Date (DateTime) and Term Period (double) that can be defined as fraction of a month. My question was exactly of how can it be handled properly with my version of the code. I know this code isn't the best, and I specified in my question that it raises lots of questions that you guys listed in your comments. So do you guys have any suggestions of how to handle all the scenarios? do you guys have any better code for the function