How to convert crystal report time formula to ssrs time formula

REGINA LONG 1 Reputation point
2022-12-12T15:21:26.117+00:00

WhileReadingRecords;
Global NumberVar timeInHrs;
Local NumberVar tempTime;
//Hours in status when start and end event are on the same day
if ((DateDiff("d",{Command.CALENDAR_DT},{Command.START_EVENT_TIME}))=0 and (DateDiff("d",{Command.CALENDAR_DT},{Command.End_EVENT_TIME}))=0)
then ( tempTime :=DateDiff("n",{Command.START_EVENT_TIME},{Command.End_EVENT_TIME});
timeInHrs := tempTime\60; )
//Hours in status on the first day
else if (DateDiff("d",{Command.CALENDAR_DT},{Command.START_EVENT_TIME})=0)
then ( tempTime := DateDiff("n",{Command.START_EVENT_TIME},{Command.TOMORROW_DT});
timeInHrs := tempTime\60; )
//Hours in status is 24 hours when calendar date is between start and end event
else if ((DateDiff("d",{Command.START_EVENT_TIME},{Command.CALENDAR_DT}))>0 and (DateDiff("d",{Command.CALENDAR_DT},{Command.End_EVENT_TIME}))>0)
then timeInHrs := 24.00
//Hours in status on the last day
else if (DateDiff("d",{Command.CALENDAR_DT},{Command.End_EVENT_TIME})=0)
then ( tempTime :=DateDiff("n",{Command.CALENDAR_DT},{Command.End_EVENT_TIME});
timeInHrs := tempTime\60; )

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,064 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Joyzhao-MSFT 15,636 Reputation points
    2022-12-13T02:54:08.793+00:00

    Hi @REGINA LONG ,
    The decision functions commonly used in SSRS are IIF and SWITCH, Switch is useful when there are three or more conditions to test because it’s simpler to read than nested IIF statements.
    For you to have multiple 'else if's, the Switch function is more useful for you.
    You will get the Day of the date field with the following expression:

    =Day(Fields!START_EVENT_TIME.Value)  
    

    So your conditional expression looks like this:

    =Switch(condition1,result1,condition2,result2,condition3,result3...)  
    

    See more: Switch function.
    DATEDIFF function.
    Best Regards,
    Joy


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.