I have a date ( 2017-04-14 ) and want to add 1 month to this date using AddMonths (1) and the resulting date is 2017-05-14 . Syntax:- DateTime.Now.AddMonths( 1 ); // 2017-04-14 Example as, public static class DateTime_Extensions { //METHOD 1 public static DateTime AddMonthsCustom ( this DateTime source, int months) { DateTime result = source.AddMonths(months); if (source.Day != DateTime.DaysInMonth(source.Year, source.Month)) return result; } //METHOD 2 public static DateTime AddMonths ( this DateTime date) { if (date.Day != DateTime.DaysInMonth(date.Year, date.Month)) return date.AddMonths( 1 ); else return date.AddMonths( 1 ); } //METHOD 3 public static DateTime AddSmartMonths ( this DateTime date, int nMonths) { int year = date.Year; int month = date.Month; int day = date.Day; if ((day == ...
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers