Next higher month day

Submitted by:Tim Kelly

Date added:20 June, 2016

Category:C#

How to find the next X day after a given Date time.

Tags: next day

Code Snippet:

/// <summary>
/// Returns the next month day after the given DateTime.
/// </summary>
/// <param name="T">Source DateTime</param>
/// <param name="D">Target month day</param>
/// <returns>DateTime</returns>
public DateTime NextHigherMonthDay(DateTime T, int D) {
return ((T.Day >= D) ? T.AddMonths(1) : T).AddDays(D-T.Day);
}

// With a minor change, you can create related functions like
// the one below. I just changed the ">=" to ">" ...
public DateTime NextHigherOrEqualMonthDay(DateTime T, int D)
{
return ((T.Day > D) ? T.AddMonths(1) : T).AddDays(D - T.Day);
}

 
 

Comments