Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Date Differences SSRS

Posted on 2016-10-17
3
Medium Priority
?
114 Views
Last Modified: 2016-10-19
Good afternoon. I am just starting to play around with SSRS. I have a report I created from a SharePoint list (if that matters). I have two date fields once called created and the other called completion_date. With in the report I went into the text box properties for both and formatted the date to read m/d/yyyy on both fields. Basically I removed the time.

I then created a text box called NumberofBusinessDays. It is in this field that I want to return a value not counting weekends on the difference between the field created and the field completion_date. So for example:

Created Date = 10/17/2016 Completion Date = 10/20/2016 then NumberofBusinessDays = 3.

How do I accomplish this for a newbie?
0
Comment
Question by:DJ P
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 41847768
Not counting weekends sounds simple enough, but it does complicate the calculation. Here is a way using a case expression:

SELECT
   ID
,     (DATEDIFF(dd, [Created Date], [Completion Date]) + 1)
    - (DATEDIFF(wk, [Created Date], [Completion Date]) * 2)
    - (CASE WHEN DATENAME(dw, [Created Date]) = 'Sunday' THEN 1 ELSE 0 END)
    - (CASE WHEN DATENAME(dw, [Completion Date]) = 'Saturday' THEN 1 ELSE 0 END)
  as NumberofBusinessDays 

  , <<other fields >>
from your_table

Open in new window

It is also possible to avoid using strings for Saturday/Sunday if that is important
0
 

Author Comment

by:DJ P
ID: 41848141
Thanks. Keep in mind I am new to this and what you provided does not work. I'm not sure if this matters but I am looking at this data via a data set from sharepoint. I am reading that the way you set things out of report writer via a sharepoint list is different than traditional sql but again I'm not sure on that since my experience is lacking. I can't even get a simple date parameter to work but that's another story. Would I be correct on this or should what you provided work? If this is the case than I am missing something.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question