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:wave:
Printable View
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:wave:
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.
If first Sunday useCode: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)
The above formulas return January 9, 2009 and January 16, 2009.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)