Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hy,

I am trying to loop between two dates, and count ONLY those (complete) months which start on 1. and finish on 30 or 31. So, for example, between 20/01/2014 and 20/05/2014 I need to get back number 3.

Thx for any help.
Posted
Comments
Kornfeld Eliyahu Peter 23-Feb-14 4:57am    
Have you done anything so far? Show some effort (search or code)! As is it ain't a question...

1 solution

Try:
C#
private int GetWholeMonths(DateTime start, DateTime end)
    {
    if (start.Day != 1)
        {
        start = new DateTime(start.Year, start.Month, 1).AddMonths(1);
        }
    return (end.Month - start.Month) + 12 * (end.Year - start.Year);
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900