How to determine week no. of a given date?

For example I have a list of dates

5/11/2006, 5/18/2006, 5/25/2006

How can I categorize these dates

sample output:

Today:

5/25/2006

Last Week:

5/18/2006




Answer this question

How to determine week no. of a given date?

  • Jaans

    I was under the impression that you wanted to determine if a given date was in the last(previous)week.

    Can you kindly mark the post as an answer if it helped you


  • Kenneth Harris

    for Today,compare with DaysOfYear for Date.Now with DayeOfYear of the passed Date.Time and if 0,then today

    Use this method to categorize weeks-

    First time pass DateTime.Now - get week

    Next time pass the date to determine-get week

    (if 1 then last week)

    public static int GetWeek(DateTime t)

    {

    int dayOfYear = t.DayOfYear;

    double week = Math.Floor(dayOfYear / 7.0)+1;

    return (int)week;

    }


  • joffa

    GetWeek will return the week number right what's (if 1 then last week) for

  • How to determine week no. of a given date?