locked
How to get week start date and week end date RRS feed

  • Question

  • Hello

    I want to fetch Week Start Date and Week End Date for the entered date in sharepoint datetime control, let me know what is the best way to do this?

    Friday, May 21, 2010 5:10 PM

Answers

  • if calculated columns are applicable in your case, it can be as easy as:

    =[mydate] - WEEKDAY([mydate], 3)

    for start day of the week (monday)

    =[mydate] - WEEKDAY([mydate], 3) + 6

    for end day of the week (sunday)

    • Marked as answer by Chengyi Wu Tuesday, May 25, 2010 2:36 AM
    Friday, May 21, 2010 8:25 PM
  • for Friday Week End date, use +4.

    =[mydate] - WEEKDAY([mydate], 3) + 4


    Moonis Tahir MVP, MCPD, MCSD.net, MCTS BizTalk 2006/SQL 2005/SharePoint Server 2007 (Dev & Config)
    • Marked as answer by Chengyi Wu Tuesday, May 25, 2010 2:36 AM
    Sunday, May 23, 2010 3:29 AM

All replies

  • You'll have to use custom .NET code to do this. What makes this question more complicated than it would originally seem is that Microsoft's object model has to take into account the fact that different cultures have a different start date to their week.

    What you could do is to start by passing in a date and determining its DayOfWeek value:
    How to: Extract the Day of the Week from a Specific Date

    Then you could use the System.Globalization.DateTimeInfo class's FirstDayOfWeek property:
    http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.firstdayofweek(VS.85).aspx 

    Here's a thread that shows you how you can figure out those dates for a whole year; you could adapt it for just one date:
    http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/f052ada3-8037-4345-9db0-ac2bd8fc2c67

    Hope this helps,
    Becky


    blog.beckybertram.com | RSS | @beckybertram
    Friday, May 21, 2010 6:25 PM
  • if calculated columns are applicable in your case, it can be as easy as:

    =[mydate] - WEEKDAY([mydate], 3)

    for start day of the week (monday)

    =[mydate] - WEEKDAY([mydate], 3) + 6

    for end day of the week (sunday)

    • Marked as answer by Chengyi Wu Tuesday, May 25, 2010 2:36 AM
    Friday, May 21, 2010 8:25 PM
  • Stefan

    I test your formula, it seems to be correct, but in my case my working days are Mon - Fri, let me know what should be end day of the week formula. Here is the result as per your formula

    Date Wek Start Date Week End Date
    5/17/2010 5/17/2010 5/23/2010
    5/18/2010 5/17/2010 5/23/2010
    5/19/2010 5/17/2010 5/23/2010
    5/20/2010 5/17/2010 5/23/2010
    5/21/2010 5/17/2010 5/23/2010
    5/22/2010 5/17/2010 5/23/2010
    5/23/2010 5/17/2010 5/23/2010
    5/24/2010 5/24/2010 5/30/2010
    5/25/2010 5/24/2010 5/30/2010
    5/26/2010 5/24/2010 5/30/2010
    5/27/2010 5/24/2010 5/30/2010
    5/28/2010 5/24/2010 5/30/2010
    5/29/2010 5/24/2010 5/30/2010
    5/30/2010 5/24/2010 5/30/2010
    5/31/2010 5/31/2010 6/6/2010
    6/1/2010 5/31/2010 6/6/2010
    6/2/2010 5/31/2010 6/6/2010
    6/3/2010 5/31/2010 6/6/2010

    Saturday, May 22, 2010 11:48 PM
  • for Friday Week End date, use +4.

    =[mydate] - WEEKDAY([mydate], 3) + 4


    Moonis Tahir MVP, MCPD, MCSD.net, MCTS BizTalk 2006/SQL 2005/SharePoint Server 2007 (Dev & Config)
    • Marked as answer by Chengyi Wu Tuesday, May 25, 2010 2:36 AM
    Sunday, May 23, 2010 3:29 AM