The other solutions should give you what you need to get the answer you expect. The problem with your code (a question you asked) is obvious if you manually perform the calculations for your example. Since StDate.Year = EndDate.Year and StDate.Month = EndDate.Month for your two dates, (12/1/2011 and 12/22/2011), you have monthsApart= 12 x 0 + 0 = 0. Then WeeksDiff = 0 * 4 = 0. I assume your comment that the answer shows empty actually means the answer is 0.

If test cases don't return the expected result check both the coding and the algorithm.

15,964,238 members