Results 1 to 2 of 2

Thread: [RESOLVED] Week Number to Day of week.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2007
    Posts
    307

    Resolved [RESOLVED] Week Number to Day of week.

    I have a cyrstal report and trying to make a formula field that I could pass the number of the week of the year to get the friday of that week.

    Appreciate your assistance

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Week Number to Day of week.

    What is the start date of the first week of the year? Jan 1 or the date of the first Sunday.

    If Jan 1, simply use DateAdd to get the start day of Week X and another DateAdd to get the Friday of that week.

    Code:
    Local numberVar WeekNo := 2;
    
    //get the start date for Week X of the year
    Local dateTimeVar StartDay:= DateAdd ("ww",WeekNo - 1 , DateTimeValue (Year(CurrentDate),1 ,1 ) );
    
    //get the first friday from that day.
    DateAdd("d", crFriday - DayofWeek(StartDay) , StartDay)
    If first Sunday use
    Code:
    Local numberVar WeekNo := 2;
    
    Local dateTimeVar FirstSunday := DateAdd("d", 7 - (DayofWeek(DateTimeValue (Year(CurrentDate),1 ,1)) - crSunday), DateTimeValue (Year(CurrentDate),1 ,1)) ;
    
    Local dateTimeVar StartDay:= DateAdd ("ww",WeekNo-1 , FirstSunday );
    
    DateAdd("d", crFriday - DayofWeek(StartDay) , StartDay)
    The above formulas return January 9, 2009 and January 16, 2009.
    Last edited by brucevde; Feb 20th, 2009 at 03:41 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width