Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calculating Days Between Dates


Hi all,

I have two dates (30/03/2006 and 05/04/2006, for example)

How do I in VBA calculate the number of days between these two dates
BUT excluding the weekends?

Any Ideas Appreciated
TIA


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=530515

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Calculating Days Between Dates

use the Networkdays function in the analysis toolpak.

--
Regards,
Tom Ogilvy



"gti_jobert" wrote:


Hi all,

I have two dates (30/03/2006 and 05/04/2006, for example)

How do I in VBA calculate the number of days between these two dates
BUT excluding the weekends?

Any Ideas Appreciated
TIA


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=530515


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Calculating Days Between Dates


No matter guys, have came up with solution now;


Code:
--------------------

i = 0: V = 0
Do
dte = sDate + i
If (DatePart("w", dte, vbMonday) 5) Then
'do nothing
Else
V = V + 1
End If
i = i + 1
Loop Until Left(dte, 8) = Left(eDate, 8)

--------------------


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile: http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=530515

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Calculating Days Between Dates

Hello,

I suggest not to take the analysis toolpak and not to count but to
calculate straightforward:

Option Explicit

Function daydiff(dtStart As Date, dtEnd As Date) As Long

daydiff = (dtEnd - Weekday(dtEnd, 2) + _
Weekday(dtStart, 2) - dtStart) _
/ 7 * 5 - min(5, Weekday(dtStart, 2)) _
+ min(5, Weekday(dtEnd, 2))

End Function

Function min(a As Long, b As Long) As Long
If a < b Then
min = a
Else
min = b
End If
End Function

Please have a look at http://www.sulprobil.com/html/date_formulas.html
and notice:
This formula is different from Excel's built-in function (analysis
toolpak). It counts from Startdate 24:00 until Enddate 24:00

HTH,
Bernd

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Calculating Days Between Dates

Tom's answer is better.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"gti_jobert" wrote
in message ...

No matter guys, have came up with solution now;


Code:
--------------------

i = 0: V = 0
Do
dte = sDate + i
If (DatePart("w", dte, vbMonday) 5) Then
'do nothing
Else
V = V + 1
End If
i = i + 1
Loop Until Left(dte, 8) = Left(eDate, 8)

--------------------


--
gti_jobert
------------------------------------------------------------------------
gti_jobert's Profile:

http://www.excelforum.com/member.php...o&userid=30634
View this thread: http://www.excelforum.com/showthread...hreadid=530515





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 136
Default Calculating Days Between Dates

Hello Bob,

Depends, I think. Since we do not know the environment of the OP, I
only suggest...

Sometimes I like to use the analysis toolpak, sometimes not:
http://www.dicks-blog.com/archives/2...-addin-part-1/

Regards,
Bernd

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Calculating Days Between Dates

But even if you don't want to use the ATP, looping through all the dates is
overkill.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

wrote in message
oups.com...
Hello Bob,

Depends, I think. Since we do not know the environment of the OP, I
only suggest...

Sometimes I like to use the analysis toolpak, sometimes not:

http://www.dicks-blog.com/archives/2...-addin-part-1/

Regards,
Bernd



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating the days between two dates pandd15 Excel Worksheet Functions 2 September 15th 09 03:18 PM
Conditional Formatting Dates calculating 10 days and 30 days from a certain date Sioux[_2_] Excel Worksheet Functions 2 October 11th 07 02:04 PM
Calculating Days Between Dates martins New Users to Excel 5 March 26th 06 11:46 PM
Calculating number of days between two dates that fall between two other dates [email protected] Excel Discussion (Misc queries) 5 October 26th 05 06:18 PM
Calculating # of busn days, not just calendar days, between 2 dates? StargateFanFromWork Excel Programming 1 June 29th 04 08:31 PM


All times are GMT +1. The time now is 12:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"