This code snippet describes how to find the next month day after the given DateTime. That can be very useful, for example, if you want to find the next 15th day or so after a specific date.
/// /// Returns the next month day after the given DateTime. /// /// Source DateTime /// Target month day /// DateTime 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); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|