Link to home
Start Free TrialLog in
Avatar of srodgers45
srodgers45

asked on

Convert date time to show letters for shifts in SSRS report builder 3.0

I am trying to convert dates to show as a shift letter. I.E.  based on a 48 hour rotation beginning at 08:00 (am) for each day it would show the corresponding shift based on the date/time.
1-2-2011 before 08:00 = "A"
1-3-2011 before 08:00 = "A"  
1-4-2011 before 08:00 = "B"  
1-5-2011 before 08:00 = "B"
1-6-2011 before 08:00 = "B"  
1-7-2011 before 08:00 = "C"
1-8-2011 before 08:00 = "C"  
then back to
1-9-2011 before 08:00 = "A"  
And repeats from there.

The screen shot I have shows how I have it set up for a formula in Crystal, it works great. I am new to SSRS and not sure how to reproduce it for those reports? Any help is appreciated.

User generated image
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

You place this code in your Reports properties Code Tab.
You will need to test it. I think I got it pretty close.
Then have this code in your cell or textbox

=Code.ShiftChange(Fields!MyFirstShiftDate.Value, Fields!MyComp_StatusDate.Value)

Public Function ShiftChange(ByVal FirstShift As DateTime, ByVal CompStatus As DateTime) As String
        Dim DayDiff As Integer = Nothing

        DayDiff = Microsoft.VisualBasic.DateDiff(DateInterval.Day, FirstShift, CompStatus) Mod 6
        Select Case DayDiff
            Case 0
                If CompStatus.Hour < 8 Then
                    Return "C"
                Else
                    Return "A"
                End If
            Case 1              
                Return "A"
            Case 2
                If CompStatus.Hour < 8 Then
                    Return "A"
                Else
                    Return "B"
                End If
            Case 3
                Return "B"
            Case 4
                If CompStatus.Hour < 8 Then
                    Return "B"
                Else
                    Return "C"
                End If
            Case 5
                Return "C"
        End Select
        Return Nothing
    End Function

Open in new window

Avatar of srodgers45
srodgers45

ASKER

In this area?  

User generated image
No. If you are using 2008 just right click on the report design area and pick Code tab.
I think i almost there - i believe I need to add a date value in the expression, correct? Forgive my ignorance

 User generated image  
Shift-ID-Formula-3.bmp
you need two different values in the expression, not both CREATED
I think I am still missing something - doesn't there need to be a date for the shift starting point  in the expression field? It should start over after 6 days  "AABBCCAABBCC............FOREVER"

I changed the expression to 2 different values:

 =Code.ShiftChange(Fields!Tdate.Value, Fields!CREATED.Value)  - ---- Should there be a shift start date value set in this expression? It would be the Tdate field if so.The screen shot example at the top from crystal formula has a static value for the shift start.

And should the code have a table value 'CREATED' to use for the shft start and stop time as well?

Sorry to be a pain, just not familiar with this application, I am going to be sooner than later. I know I am close to getting it right. Thank You for the help so far.

what I am trying to show in the screen shot is:
The 4th should be C prior to 0800 on the 5th,
Then
The 5th and 6th after 0800 are A,
The 7th and 8th after 0800 are B,
The 9th and 10th after 0800 are C,
Then it starts over again

 User generated image
This is the report I am showing results for:
 User generated image
You need to get me a start point.
Like the shift start is 1/4/2011 and the created date is 1/4/2011
You only show me the fininshed date.
In other words I need to see what you want going in and what the real answer is suppose to be outing out.
The start date would be 2010-12-31 would be the first A shift  date, the created date has the date and time for which the shift would correspond to. So on 12-31-2010 @ 0800 A shift starts for 48 hours. What I show on the report is any created date within that 48 hours has the corresponding shift. On 1-2-2011 at 0800 B shift starts, and so on.Does that make sense? The date and setup on the screen shot at the top of the page for the crystal formula is accurate for the current report I have in crystal. I just cannot use it for what I need now. I am trying to basically duplicate that formula for SSRS report.

Thanks
Ok the code is showing the same now as the very top code of
 '1-2-2011 before 08:00 = "A"
    '1-3-2011 before 08:00 = "A"  
    '1-4-2011 before 08:00 = "B"  
    '1-5-2011 before 08:00 = "B"
    '1-6-2011 before 08:00 = "B"  
    '1-7-2011 before 08:00 = "C"
    '1-8-2011 before 08:00 = "C"  
    'then back to
    '1-9-2011 before 08:00 = "A"  
    'And repeats from there.

Let me know if that still does not work.
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Still the same result?

Forgive me, I must be explaining it wrong? I dont understand how the code knows what to use for a start date for the first A shift date? is it based on this expression formula? Should there be a date defined for the value? I am trying to understand it

     =Code.ShiftChange(Fields!Tdate.Value, Fields!CREATED.Value)

    12-31-2010 @ 0800 is the "First A Shift day" (for the next 48 hours it is A shift) based on Fire Department Shifts, I am reporting on incomplete reports for any incident generated from then until:    

     1-1-2011 before 08:00 = "A"  
Then
    '1-2-2011 before 08:00 = "A"  
Then
    '1-3-2011 before 08:00 = "B"  
Then
    '1-4-2011 before 08:00 = "B"
Then
    '1-5-2011 before 08:00 = "B"
Then
    '1-6-2011 before 08:00 = "C"
Then
    '1-7-2011 before 08:00 = "C"  
        'And then repeats from there.

In this crystal formula it has a start date for A shift of 1-5-2010
 User generated image

This is what the report from crystal looks like, The colored box shows the shift working on the date shown on the left, which is the from "CREATED"  date/time table
 User generated image
the firstshift date was the 12-31-2010
Correct, first A shift is 12-31-2010 Thanks
Did you give up on me? I know I have. Sorry for any confusion
Thanks, I think I wore you out on this. I reposted hopefully with a better expalnation of what I am trying to do.