Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 13th, 2005, 10:21 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
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.



Reply With Quote
  #2 (permalink)  
Old July 13th, 2005, 05:48 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
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=32751

Wind is your friend
Matt
Reply With Quote
  #3 (permalink)  
Old July 14th, 2005, 04:11 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Okay will take care of this.

Reply With Quote
  #4 (permalink)  
Old July 14th, 2005, 05:23 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Does 16-07 and 17-07 return the same results as 15-07?

Maybe you're using a wrong date format and your date is silently converted.

For example 12-7 *could* be december 7, depending on your regional settings. However, 15-07 cannot mean anything else than july 15th.

The conversion can be done by the database if you're not aware of it. Try to use the ISO format (YYYYMMDD) and see if that makes a difference....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Reply With Quote
  #5 (permalink)  
Old July 18th, 2005, 05:11 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

No, 16-07 and 17-07 returns 1.
If I be using wrong date format, it should not work for other dates, i.e.14-07 and 16-07,etc.

Can you work out with this function and check at your end so that you can find out what is wrong exctly.

Thanks in advance.


Reply With Quote
  #6 (permalink)  
Old July 19th, 2005, 06:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Rupen,

Not just for 15th, looks like it does behave that way for any fridays.

When you mention 14-07 and 15-07 there, what is the result expected? If that is to be 2, I am afraid if that works, coz, I see 1 for that.

I think the catch is here.
Code:
if (d = 1 or d = 7) then
Looks like the week starts there with saturday as 1, thus sunday is 2, not 7
Code:
if (d = 1 or d = 2) then
This did the trick. I got to stick to this, as 13-07 was showing 5 as value of d within the FOR loop, when i=0.

BTW, I had to comment the DB related lines, as I don't have any idea what it contains in the holidaymaster table. I assume you have the holidays other than saturday sundays in it. So that shouldn't be a problem for the dates I used.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #7 (permalink)  
Old July 21st, 2005, 06:48 AM
Registered User
Points: 1,897, Level: 17
Points: 1,897, Level: 17 Points: 1,897, Level: 17 Points: 1,897, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Mumbai, Maharastra, India.
Posts: 352
Thanks: 14
Thanked 0 Times in 0 Posts
Send a message via Yahoo to rupen
Default

Hi Vijay,

You are right it is not counting any Friday. But I am amazed, why so?

For 14-07 to 15-07 it should return 2, and not 1.

For if (d = 1 or d = 7) then
1 refers to Sunday and 7 is to Saturday,

Pls refer this:
http://powerasp.com/content/new/vbscript-constants.asp

Now, the catch is here:

          for i = 0 to iFD

It should be:

          for i = 0 to iFD - 1

This will work fine!!!

Pleas pass your view on this.









Rupen Anjaria.
We CAN'T avoid problems, but of course can solve it.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:20 PM.


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