Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2006, 07:40 AM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sharath82
Default customized data/time diff

A query is been posted.The time is captured as From_time.When some one answers for the query that time is captured as To_Time.I need the difference between these to as


Official timings are 9.00 am to 6.00 pm
1.only official time is taken into consideration.A query posted after office hours is taken as 6.00 pm.
2.saturdays and sundays are not considered.
3.i have a table as holiday master,so those days are not considered.


Ex:a query is being posted at 4 pm today and it is solved at 2pm tomorrow.
so my answer should be 7 hours.


a query is being posted on friday 3 pm and and is solved on next tuesday 11 am.so friday 3 hours.monday 9 hours and tuesday 2 hours.so totally diff is 14 hours.


can we do with sql query alone or need to use asp as well.
I need to implement this.Please help me out.


Regards,

Sharath.



 
Old July 24th, 2006, 02:57 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This assumes that neither from_time nor to_time is on weekend

select name,
    CASE
        WHEN DATEDIFF(day, from_time, to_time) = 0 THEN DATEDIFF(mi, from_time, to_time)
        ELSE 540 * (select count(*) - 2 from fnSeqDates(from_time, to_time) where seqdate between 2 and 6) + -- Number of minutes for whole day, not including from_time and to_time
            1080 - datediff(mi, '09:00:00', from_time) % 1440 + -- Numbers of minutes from from_time to closing at 6 pm same day.
            datediff(mi, '09:00:00', to_time) % 1440 -- Number of minutes since 9 am to to_time same day
    END Mins
FROM MyTable

with the help of my function found here http://www.sqlservercentral.com/colu...tiliretire.asp





Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening a customized page Snuffles ASP.NET 2.0 Basics 8 April 1st, 2007 10:53 AM
Get your customized software aprababu C# 0 November 15th, 2006 07:57 AM
Customized sorting Pavek XSLT 2 June 10th, 2006 05:09 AM
customized skin parag.nikhal Classic ASP Basics 0 December 19th, 2005 10:19 AM
add same data in diff table / search yylee Access VBA 8 April 13th, 2004 02:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.