Question

Is there anything like the Oracle "NEXT_DAY" function available in the syntax that Crystal Reports uses?

I'm trying to write a formula to output the following Monday @ 9:00am if the datetime tested falls between Friday @ 9:00pm and Monday @ 9:00am.

So far I have

IF DAYOFWEEK ({DATETIMEFROMMYDB}) IN [7,1]
    OR (DAYOFWEEK({DATETIMEFROMMYDB}) = 6 AND TIME({DATETIMEFROMMYDB}) in time(21,00,00) to time(23,59,59))
    OR (DAYOFWEEK({DATETIMEFROMMYDB}) = 2 AND TIME({DATETIMEFROMMYDB}) in time(00,00,00) to time(08,59,59))
THEN ...

I know I can write seperate IF statements to do a different amount of DateAdd for each of Fri, Sat, Sun, Mon, but if I can keep it concise by lumping all of these into one I would much prefer it. I'm already going to be adding additional rules for if the datetime falls outside of business hours on the other weekdays so I want to do as much as possible to prevent this from becoming a very overgrown and ugly formula.

Was it helpful?

Solution

Since there is no CR equivalent that I know of, you can just cheat and borrow the NEXT_DAY() function from the Oracle database. You can do this by creating a SQL Expression and then entering something like:

-- SQL Expression {%NextDay}
(SELECT NEXT_DAY("MYTABLE"."MYDATETIME", 'MONDAY')
 FROM DUAL)

then you could either use that directly in your formula:

IF DAYOFWEEK ({MYTABLE.MYDATETIME}) IN [7,1]
    OR (DAYOFWEEK({MYTABLE.MYDATETIME}) = 6 AND TIME({MYTABLE.MYDATETIME}) in time(21,00,00) to time(23,59,59))
    OR (DAYOFWEEK({MYTABLE.MYDATETIME}) = 2 AND TIME({MYTABLE.MYDATETIME) in time(00,00,00) to time(08,59,59))
THEN DateTime(date({%NextDay}),time(09,00,00))

Or, the even better way would be to just stuff ALL of the logic into the SQL Expression and do away with the formula altogether.

OTHER TIPS

  • Considering Sunday is 1

  • And the first 7 is the week we want to back

    7 = 1 week 14 = 2 weeks

  • The last Number (1) is 1 for Sunday, 2 for Monday, 3 for Tuestday

Last Sunday 1 week ago Today - 7 + ( 7 - WEEKDAY(TODAY) )+1

Last Monday 2 weeks ago Today - 14 + ( 7 - WEEKDAY(TODAY) )+2

So this 2 formulas give me MONDAY LAST WEEK and SUNDAY LAST WEEK.

EvaluateAfter({DATETIMEFROMMYDB}) ;
If DayOfWeek ({DATETIMEFROMMYDB}) In [crFriday,crSaturday,crSunday,crMonday]
then
IF DayOfWeek ({DATETIMEFROMMYDB}) In [crFriday] 
AND TIME({DATETIMEFROMMYDB}) >= time(21,00,00)
then //your code here
Else if Not(DayOfWeek ({DATETIMEFROMMYDB}) In [crFriday] )
AND (TIME({DATETIMEFROMMYDB}) >= time(00,00,00) AND TIME({DATETIMEFROMMYDB}) <= time(23,59,59))
then //your code here
Else if DayOfWeek ({DATETIMEFROMMYDB})In [crMonday] 
AND TIME({DATETIMEFROMMYDB}) < time(09,00,00)
then //your code here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top