Search code examples
c#dategregorian-calendar

Last sunday of a year in c#


How can I get date of last sunday of a year in C#?? Will gregoriancalendar class be of help?


Solution

  • I don't know if there is a method for that but a simple way is to check the last 7 days of December, starting from 31st day and counting down.

    Update: actually if the days of week are numbered like this:

    0 Sun, 1 Mon, ... 6 Sat
    

    then

    lastSunday = 31 - DayOfWeek(31, 12, 2009) // pseudocode