Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Please help me (Date Difference Issue)


Please help me (Date Difference Issue)

Author
Message
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24157 Visits: 37926
mota7128 (5/17/2012)
Hi Guys,

I am using SQL 2008 R2, and I do thank all of you guys, REALLY love you.

Much thanks for you "Lynn Pettis", your solution is awesome for me and I think that I can amend it to exclude Saturday and Sunday

Best Regards,
Hatem


Look close, I did that already (hopefully) in the code I just posted. Be sure to test it in your environment.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Obs
Obs
SSC Veteran
SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)SSC Veteran (249 reputation)

Group: General Forum Members
Points: 249 Visits: 424
Sorry, just got back. I didn't really read through your second post, but I think this is right/close/gives you an idea. Also, SQL 2008 R2 makes it easier.

DECLARE   @timeend TIME = '17:00'
DECLARE   @timestart TIME = '08:30'
DECLARE @daylength INT = DATEDIFF(mi, @timestart, @timeend)
DECLARE   @StartDate DATETIME= '2012-05-10 8:30:00.000';
DECLARE   @EndDate DATETIME= '2012-05-14 15:00:00.000';

SELECT
   (DATEDIFF(d, @StartDate, @enddate) * @daylength) --TotalMinutes,
   - (DATEDIFF(week, @StartDate, @enddate) * 2 * @daylength) --Weekend
- (@daylength - DATEDIFF(mi, @timestart, CAST(@EndDate AS TIME))) --LastDay
- DATEDIFF(mi,@timeend, CAST(@startdate AS TIME) ) -- First Day


Always remember to test.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search