PC Review


Reply
Thread Tools Rate Thread

calculate number of days formula

 
 
Ranae
Guest
Posts: n/a
 
      25th Apr 2010
hi,
Can someone please help me with a formula to calculate number of days,
excluding weekend days?

A1 B1 C1
Start date End date Total days (excluding weekend)
 
Reply With Quote
 
 
 
 
ozgrid.com
Guest
Posts: n/a
 
      25th Apr 2010
Use the NETWORKDAY Function.


--
Regards
Dave Hawley
www.ozgrid.com
"Ranae" <(E-Mail Removed)> wrote in message
news:E0B00D73-E269-4EDA-8498-(E-Mail Removed)...
> hi,
> Can someone please help me with a formula to calculate number of days,
> excluding weekend days?
>
> A1 B1 C1
> Start date End date Total days (excluding weekend)


 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      25th Apr 2010
That looks like a typo (missing S), try

=NETWORKDAYS(start_date,end_date,holidays)

Regards,
Peter T

"ozgrid.com" <(E-Mail Removed)> wrote in message
news:B17C62DB-4CA2-4A62-8369-(E-Mail Removed)...
> Use the NETWORKDAY Function.
>
>
> --
> Regards
> Dave Hawley
> www.ozgrid.com
> "Ranae" <(E-Mail Removed)> wrote in message
> news:E0B00D73-E269-4EDA-8498-(E-Mail Removed)...
>> hi,
>> Can someone please help me with a formula to calculate number of days,
>> excluding weekend days?
>>
>> A1 B1 C1
>> Start date End date Total days (excluding weekend)

>



 
Reply With Quote
 
Bernd P
Guest
Posts: n/a
 
      25th Apr 2010
Hello,

If you do no need to take into account holidays, I suggest to use the
4th formula shown at
http://sulprobil.com/html/date_formulas.html

Regards,
Bernd
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      25th Apr 2010
Bernd,

I thought you might be interested in seeing this short one-liner alternative
to your "cwd" function (which requires your "min" function to operate); it
is fully self-contained and, as such, relies only on built-in VB
functions...

Function CWD(D1 As Date, D2 As Date) As Long
CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
(Weekday(D2) <> 7) + (Weekday(D1) = 1) + (Weekday(D1, 2) < 6)
End Function

Note that if you remove the last addend, that is the "+(Weekday(d1, 2)<6)"
logical expression, then the function will return the same results as
Excel's NETWORKDAYS function. If we provide the function with an Optional
parameter, we can make it return either result (yours or NETWORKDAYS's) like
so...

Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
(Weekday(D2) <> 7) + (Weekday(D1) = 1) - NWD * (Weekday(D1, 2) < 6)
End Function

The default for the NWD (short for NetWorkDays by the way) parameter is
False, meaning it returns the same results as does your "cwd" function...
pass True in for the NWD parameter and the function returns the same values
as Excel's NETWORKDAYS function.

--
Rick (MVP - Excel)



"Bernd P" <(E-Mail Removed)> wrote in message
news:f93a41d8-ea2f-4b16-9da9-(E-Mail Removed)...
> Hello,
>
> If you do no need to take into account holidays, I suggest to use the
> 4th formula shown at
> http://sulprobil.com/html/date_formulas.html
>
> Regards,
> Bernd


 
Reply With Quote
 
Bernd P
Guest
Posts: n/a
 
      25th Apr 2010
Hello Rick,

Thanks, I like that one! I put your cute and shorter version on my
site as well (same page as above).

Your version with the optional parameter NWD is not working as
expected, though:
It returns for 23/08/1933 - 14/10/1933 (NWD is False) 38 days and not
37 as the other versions do, for example.

Regards,
Bernd

On 25 Apr., 19:30, "Rick Rothstein"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> Bernd,
>
> I thought you might be interested in seeing this short one-liner alternative
> to your "cwd" function (which requires your "min" function to operate); it
> is fully self-contained and, as such, relies only on built-in VB
> functions...
>
> Function CWD(D1 As Date, D2 As Date) As Long
> * CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
> * * * * (Weekday(D2) <> 7) + (Weekday(D1) = 1) + (Weekday(D1, 2) < 6)
> End Function
>
> Note that if you remove the last addend, that is the "+(Weekday(d1, 2)<6)"
> logical expression, then the function will return the same results as
> Excel's NETWORKDAYS function. If we provide the function with an Optional
> parameter, we can make it return either result (yours or NETWORKDAYS's) like
> so...
>
> Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
> * CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
> * * * * (Weekday(D2) <> 7) + (Weekday(D1) = 1) - NWD * (Weekday(D1, 2) < 6)
> End Function
>
> The default for the NWD (short for NetWorkDays by the way) parameter is
> False, meaning it returns the same results as does your "cwd" function...
> pass True in for the NWD parameter and the function returns the same values
> as Excel's NETWORKDAYS function.
>
> --
> Rick (MVP - Excel)
>
> "Bernd P" <bplumh...@gmail.com> wrote in message
>
> news:f93a41d8-ea2f-4b16-9da9-(E-Mail Removed)...
>
> > Hello,

>
> > If you do no need to take into account holidays, I suggest to use the
> > 4th formula shown at
> >http://sulprobil.com/html/date_formulas.html

>
> > Regards,
> > Bernd


 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      25th Apr 2010
It should be noted that in my function, D1 must be the earlier date and D2
the later one (the DateDiff function requires this). Perhaps changing the
parameter names would help enforce this requirement...

Function CWD(StartDate As Date, EndDate As Date, _
Optional NWD As Boolean) As Long
CWD = DateDiff("d", StartDate, EndDate) - DateDiff("ww", StartDate, _
EndDate) * 2 - (Weekday(EndDate) <> 7) + (Weekday(StartDate) = 1) _
- NWD * (Weekday(StartDate, 2) < 6)
End Function

--
Rick (MVP - Excel)



"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Bernd,
>
> I thought you might be interested in seeing this short one-liner
> alternative to your "cwd" function (which requires your "min" function to
> operate); it is fully self-contained and, as such, relies only on built-in
> VB functions...
>
> Function CWD(D1 As Date, D2 As Date) As Long
> CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
> (Weekday(D2) <> 7) + (Weekday(D1) = 1) + (Weekday(D1, 2) < 6)
> End Function
>
> Note that if you remove the last addend, that is the "+(Weekday(d1, 2)<6)"
> logical expression, then the function will return the same results as
> Excel's NETWORKDAYS function. If we provide the function with an Optional
> parameter, we can make it return either result (yours or NETWORKDAYS's)
> like so...
>
> Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
> CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
> (Weekday(D2) <> 7) + (Weekday(D1) = 1) - NWD * (Weekday(D1, 2) < 6)
> End Function
>
> The default for the NWD (short for NetWorkDays by the way) parameter is
> False, meaning it returns the same results as does your "cwd" function...
> pass True in for the NWD parameter and the function returns the same
> values as Excel's NETWORKDAYS function.
>
> --
> Rick (MVP - Excel)
>
>
>
> "Bernd P" <(E-Mail Removed)> wrote in message
> news:f93a41d8-ea2f-4b16-9da9-(E-Mail Removed)...
>> Hello,
>>
>> If you do no need to take into account holidays, I suggest to use the
>> 4th formula shown at
>> http://sulprobil.com/html/date_formulas.html
>>
>> Regards,
>> Bernd

>

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      25th Apr 2010
Sorry, it looks like I implemented the NWD parameter backwards. This should
produce the correct results for the NWD parameter equaling True and False...

Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - (Weekday(D2) _
<> 7) + (Weekday(D1) = 1) - (Not NWD) * (Weekday(D1, 2) < 6)
End Function

And here it is with the renamed parameters to enforce the requirement that
D1 must be the earlier date and D2 the later one...

Function CWD(StartDate As Date, EndDate As Date, _
Optional NWD As Boolean) As Long
CWD = DateDiff("d", StartDate, EndDate) - DateDiff("ww", StartDate, _
EndDate) * 2 - (Weekday(EndDate) <> 7) + (Weekday(StartDate) = 1) _
- (Not NWD) * (Weekday(StartDate, 2) < 6)
End Function

--
Rick (MVP - Excel)



"Bernd P" <(E-Mail Removed)> wrote in message
news:dd920ad7-b432-4663-bcc3-(E-Mail Removed)...
> Hello Rick,
>
> Thanks, I like that one! I put your cute and shorter version on my
> site as well (same page as above).
>
> Your version with the optional parameter NWD is not working as
> expected, though:
> It returns for 23/08/1933 - 14/10/1933 (NWD is False) 38 days and not
> 37 as the other versions do, for example.
>
> Regards,
> Bernd
>
> On 25 Apr., 19:30, "Rick Rothstein"
> <rick.newsNO.S...@NO.SPAMverizon.net> wrote:
>> Bernd,
>>
>> I thought you might be interested in seeing this short one-liner
>> alternative
>> to your "cwd" function (which requires your "min" function to operate);
>> it
>> is fully self-contained and, as such, relies only on built-in VB
>> functions...
>>
>> Function CWD(D1 As Date, D2 As Date) As Long
>> CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
>> (Weekday(D2) <> 7) + (Weekday(D1) = 1) + (Weekday(D1, 2) < 6)
>> End Function
>>
>> Note that if you remove the last addend, that is the "+(Weekday(d1,
>> 2)<6)"
>> logical expression, then the function will return the same results as
>> Excel's NETWORKDAYS function. If we provide the function with an Optional
>> parameter, we can make it return either result (yours or NETWORKDAYS's)
>> like
>> so...
>>
>> Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
>> CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - _
>> (Weekday(D2) <> 7) + (Weekday(D1) = 1) - NWD * (Weekday(D1, 2) <
>> 6)
>> End Function
>>
>> The default for the NWD (short for NetWorkDays by the way) parameter is
>> False, meaning it returns the same results as does your "cwd" function...
>> pass True in for the NWD parameter and the function returns the same
>> values
>> as Excel's NETWORKDAYS function.
>>
>> --
>> Rick (MVP - Excel)
>>
>> "Bernd P" <bplumh...@gmail.com> wrote in message
>>
>> news:f93a41d8-ea2f-4b16-9da9-(E-Mail Removed)...
>>
>> > Hello,

>>
>> > If you do no need to take into account holidays, I suggest to use the
>> > 4th formula shown at
>> >http://sulprobil.com/html/date_formulas.html

>>
>> > Regards,
>> > Bernd

>

 
Reply With Quote
 
Bernd P
Guest
Posts: n/a
 
      25th Apr 2010
Hello Rick,

Great. Tested and published as well. No need anymore for my cwd
version. Thanks.

Regards,
Bernd

On 25 Apr., 21:15, "Rick Rothstein"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> Sorry, it looks like I implemented the NWD parameter backwards. This should
> produce the correct results for the NWD parameter equaling True and False....
>
> Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
> * CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - (Weekday(D2) _
> * * * * * * *<> 7) + (Weekday(D1) = 1) - (Not NWD) * (Weekday(D1, 2) < 6)
> End Function
>
> And here it is with the renamed parameters to enforce the requirement that
> D1 must be the earlier date and D2 the later one...
>
> Function CWD(StartDate As Date, EndDate As Date, _
> * * * * * * *Optional NWD As Boolean) As Long
> * CWD = DateDiff("d", StartDate, EndDate) - DateDiff("ww", StartDate,_
> * * * * EndDate) * 2 - (Weekday(EndDate) <> 7) + (Weekday(StartDate) = 1) _
> * * * * - (Not NWD) * (Weekday(StartDate, 2) < 6)
> End Function
>
> --
> Rick (MVP - Excel)

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      25th Apr 2010
You are quite welcome... it was a fun "challenge" even though you didn't
present your posting as a challenge.

--
Rick (MVP - Excel)



"Bernd P" <(E-Mail Removed)> wrote in message
news:bcef26ab-edb3-4674-986b-(E-Mail Removed)...
> Hello Rick,
>
> Great. Tested and published as well. No need anymore for my cwd
> version. Thanks.
>
> Regards,
> Bernd
>
> On 25 Apr., 21:15, "Rick Rothstein"
> <rick.newsNO.S...@NO.SPAMverizon.net> wrote:
>> Sorry, it looks like I implemented the NWD parameter backwards. This
>> should
>> produce the correct results for the NWD parameter equaling True and
>> False...
>>
>> Function CWD(D1 As Date, D2 As Date, Optional NWD As Boolean) As Long
>> CWD = DateDiff("d", D1, D2) - DateDiff("ww", D1, D2) * 2 - (Weekday(D2)
>> _
>> <> 7) + (Weekday(D1) = 1) - (Not NWD) * (Weekday(D1, 2) < 6)
>> End Function
>>
>> And here it is with the renamed parameters to enforce the requirement
>> that
>> D1 must be the earlier date and D2 the later one...
>>
>> Function CWD(StartDate As Date, EndDate As Date, _
>> Optional NWD As Boolean) As Long
>> CWD = DateDiff("d", StartDate, EndDate) - DateDiff("ww", StartDate, _
>> EndDate) * 2 - (Weekday(EndDate) <> 7) + (Weekday(StartDate) = 1)
>> _
>> - (Not NWD) * (Weekday(StartDate, 2) < 6)
>> End Function
>>
>> --
>> Rick (MVP - Excel)


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula to calculate number of days & ignore blank cells =?Utf-8?B?TWlmdHk=?= Microsoft Excel Misc 7 13th Feb 2006 10:36 PM
Formula to calculate number of days between Dates themax16 Microsoft Excel Worksheet Functions 2 21st Oct 2005 01:38 PM
Re: Excel Aged Receivable formula to calculate 0-30 days, 61-60 days,. Haldun Alay Microsoft Excel Worksheet Functions 0 16th Sep 2004 08:43 AM
Re: how to calculate the number of days between dates (dd/mm/yyyy) using a formula JE McGimpsey Microsoft Excel Misc 7 11th Mar 2004 01:25 PM
Re: how to calculate the number of days between dates (dd/mm/yyyy) using a formula Frank Kabel Microsoft Excel Misc 0 10th Mar 2004 06:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:38 PM.