Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic 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 13th, 2005, 10:24 AM
Registered User
 
Join Date: Apr 2005
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default Date difference.

Hi,
Below is a function which counts working days(i.e. don't count sunday and saturday) between specified dates.
--------------------------------------------------
Function GetWorkingDay(dtFrom1,dtTo1)
            dim cd
            dim iFD
            dim cntr1
            dim i
            dim d
            dim wday
            dim objRSHL
            set objRSHL = Server.CreateObject("ADODB.Recordset")
            'IFD STORES NUMBER OF DAY IN CURRENT MONTH. SAY 30 FOR JUNE
            'iFD = datepart("d",dateserial(year(cd),month(cd)+1,1-1))
            iFD = DateDiff("d",dtFrom1,dtTo1) + 1

            cntr1 = 0

            for i = 0 to iFD
                    'd = datepart("w",dateadd("d",i,dateserial(year(cd),mon th(cd),1)))
                    d = datepart("w",dateadd("d",i,CDate(dtFrom1)))
                    'IF IT IS SUNDAY OR SATURDAY INCREMENT COUNTER
                    if (d = 1 or d = 7) then
                        cntr1 = cntr1 + 1
                    end if
            next
            wday = iFD - cntr1

            'GET HOLIDAYS BETWEEN THE DATE SPECIFIED
            objRSHL.open "select count(holidayid) from holidaymaster where HolidayType = 1 and HolidayDate between #" & CDate(dtFrom1) & "# and #" & CDate(dtTo1) & "#" ,objConn

            if not objRSHL.EOF then
                wday = wday - objRSHL.fields(0).value
            end if
            objRSHL.close

            GetWorkingDay = wday
End Function

--------------------------------------------------
It works fine for almost all date range. Except 15-Jul-05, strange but don't know why.
e.g. if you pass value as 12-Jul-05 to 12-Jul-05 it will return 1
but if 15-Jun-05 to 15-Jun-05 will return 0.

Thankx in advance.


 
Old July 13th, 2005, 05:49 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Please do not cross post:
http://p2p.wrox.com/topic.asp?TOPIC_ID=32750

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Date difference surya Javascript How-To 2 September 19th, 2008 12:42 AM
get date difference benz_jie2005 Access 1 January 16th, 2008 09:33 AM
Date Difference Help saf01 Crystal Reports 0 September 29th, 2005 05:35 AM
Difference between Date and Now() marcin2k Access VBA 3 September 8th, 2005 01:05 PM
Date difference. rupen Classic ASP Basics 6 July 21st, 2005 06:48 AM





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