If you have one day and want to select a whole week in crystal reports then you can do like this.
{@Today} is any date in a week and the only date we know.
This returns the date of the first day in the week if the first day is a Monday.
If DayOfWeek({@Today}) = 2 Then {@Today} Else If DayOfWeek({@Today}) = 3 Then dateadd ("d",-1,{@Today}) Else If DayOfWeek({@Today}) = 4 Then dateadd ("d",-2,{@Today}) Else If DayOfWeek({@Today}) = 5 Then dateadd ("d",-3,{@Today}) Else If DayOfWeek({@Today}) = 6 Then dateadd ("d",-4,{@Today}) Else If DayOfWeek({@Today}) = 7 Then dateadd ("d",-5,{@Today}) Else If DayOfWeek({@Today}) = 1 Then dateadd ("d",-6,{@Today})
This returns the last date in the week (if its a Sunday) and the last time of the week.
Local DateTimeVar d := DateTime (DatePart ("yyyy", {@Today}), _ DatePart ("m", {@Today}), DatePart ("d", {@Today}), 23, 59, 59); If DayOfWeek({@Today}) = 2 Then dateadd ("d",+6,d) Else If DayOfWeek({@Today}) = 3 Then dateadd ("d",+5,d) Else If DayOfWeek({@Today}) = 4 Then dateadd ("d",+4,d) Else If DayOfWeek({@Today}) = 5 Then dateadd ("d",+3,d) Else If DayOfWeek({@Today}) = 6 Then dateadd ("d",+2,d) Else If DayOfWeek({@Today}) = 7 Then dateadd ("d",+1,d) Else If DayOfWeek({@Today}) = 1 Then d;
This entry was posted in Crystal syntax and tagged crystal, crystal reports, datepart, datetime, last date, last time, yyyy. Bookmark the permalink