System.Globalization.CCGregorianCalendar.AddMonths C# (CSharp) Method

AddMonths() public static method

Adds months to the given date.
public static AddMonths ( System time, int months ) : System.DateTime
time System The /// to which to add /// months. ///
months int The number of months to add.
return System.DateTime
	public static System.DateTime AddMonths(System.DateTime time,
		int months)
	{
		int rd = CCFixed.FromDateTime(time);
		int day, month, year;
		dmy_from_fixed(out day, out month, out year, rd);
		month += months;
		year += CCMath.div_mod(out month, month, 12);
		int maxday = GetDaysInMonth (year, month);
		if (day > maxday)
			day = maxday;
		rd = fixed_from_dmy(day, month, year);
		System.DateTime t = CCFixed.ToDateTime(rd);
		return t.Add(time.TimeOfDay);
	}

Usage Example

        /// <summary>Returns a <see cref="T:System.DateTime" /> that is the specified number of months away from the specified <see cref="T:System.DateTime" />.</summary>
        /// <returns>The <see cref="T:System.DateTime" /> that results from adding the specified number of months to the specified <see cref="T:System.DateTime" />.</returns>
        /// <param name="time">The <see cref="T:System.DateTime" /> to which to add months. </param>
        /// <param name="months">The number of months to add. </param>
        /// <exception cref="T:System.ArgumentException">The resulting <see cref="T:System.DateTime" /> is outside the supported range. </exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="months" /> is less than -120000.-or- <paramref name="months" /> is greater than 120000. </exception>
        public override DateTime AddMonths(DateTime time, int months)
        {
            DateTime dateTime = CCGregorianCalendar.AddMonths(time, months);

            this.M_CheckDateTime(dateTime);
            return(dateTime);
        }
All Usage Examples Of System.Globalization.CCGregorianCalendar::AddMonths