Get week dates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MFRASER

    Get week dates

    If I have a date how can I find out the beginning of the week and the end of
    the week?



    System.DateTime StartDate = new DateTime(2003,1 0,29);

    System.DateTime StartWeek = ?

    System.DateTime EndWeek = ?




  • Matt Burland

    #2
    Re: Get week dates

    The DateTime.DayOfW eek property will give you an enum that ranges from 0
    (Sunday) to 6 (Saturday). So you should be able to:

    int DaysToStartOfWe ek = (int) StartDate.DayOf Week;

    int DaysToEndOfWeek = (int)DayOfWeek. Saturday - (int)StartDate. DayOfWeek;

    DateTime StartWeek = Today.Subtract( new TimeSpan(DaysTo StartOfWeek,0,0 ,0));

    DateTime EndWeek = Today.Add(new TimeSpan(DaysTo EndOfWeek,0,0,0 ));

    You'll have to mess around with it a bit if you wanted the date on Monday
    for the start of the week and Sunday for the end of the week (just add one
    to DaysToStartOfWe ek and DaysToEndOfWeek )




    "MFRASER" <mfraser@henwoo denergy.com> wrote in message
    news:OBmZrMynDH A.3688@TK2MSFTN GP11.phx.gbl...[color=blue]
    > If I have a date how can I find out the beginning of the week and the end[/color]
    of[color=blue]
    > the week?
    >
    >
    >
    > System.DateTime StartDate = new DateTime(2003,1 0,29);
    >
    > System.DateTime StartWeek = ?
    >
    > System.DateTime EndWeek = ?
    >
    >
    >
    >[/color]


    Comment

    Working...