Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

number of working days between two dates

158 views
Skip to first unread message

Harm Olthof

unread,
Feb 18, 2012, 8:50:23 AM2/18/12
to
Hello group,
Can you point me to an efficient way to calculate the number of working
days between two dates? Taking into account saturday, sunday and special
days like Christmas, Easter? (a persons individual holiday do not have
to be taken into account).

So something like this:
set start "17-02-2012"
set end "21-02-2012"
numberofworkingdays $start $end -> 2 (or 3 if $end is inclusive)

and
set start "24-12-2012"
set end "27-12-2012"
numberofworkingdays $start $end -> 1 (or 2 if $end is inclusive)

thanks,
Harm Olthof

Gerald W. Lester

unread,
Feb 18, 2012, 2:28:26 PM2/18/12
to
On 2/18/12 7:50 AM, Harm Olthof wrote:
> Hello group,
> Can you point me to an efficient way to calculate the number of working days
> between two dates? Taking into account saturday, sunday and special days
> like Christmas, Easter? (a persons individual holiday do not have to be
> taken into account).

Working days should also take into account "bank holidays" and/or
"government holidays" -- these are locale dependent.

Also you mention Easter -- which is always on a Sunday. I assume you mean
some off day around Easter, like Good Friday -- again this is locale dependent.


--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+

M. Strobel

unread,
Feb 18, 2012, 4:38:47 PM2/18/12
to
FWIW, I did a comparable calculation: given the term of a job in number of days (or
hours), find the termination date.

I used a calendar in postgresql, where I inserted all monday-friday days, then
deleted all holidays using an official list. We even have different holidays in
different laender of germany. And the calculation was done in pltcl.

I don't think there is a all-in-one-formula solution.

/Str.

Harm Olthof

unread,
Feb 18, 2012, 6:40:11 PM2/18/12
to
On 18-2-2012 20:28, Gerald W. Lester wrote:
> On 2/18/12 7:50 AM, Harm Olthof wrote:
>> Hello group,
>> Can you point me to an efficient way to calculate the number of
>> working days
>> between two dates? Taking into account saturday, sunday and special days
>> like Christmas, Easter? (a persons individual holiday do not have to be
>> taken into account).
>
> Working days should also take into account "bank holidays" and/or
> "government holidays" -- these are locale dependent.
>
> Also you mention Easter -- which is always on a Sunday. I assume you
> mean some off day around Easter, like Good Friday -- again this is
> locale dependent.
>
>
You are right, I did not give an exact enough description of my problem.
I should have mentioned the locale dependency.
I did not realize that there is a difference in Easter. Here, in the
Netherlands we have two days for Easter, one on sundays and one on mondays.

Harm Olthof

unread,
Feb 18, 2012, 6:49:07 PM2/18/12
to
My Tcl script reads data from Oracle and writes to Excel.
In Oracle similar solutions as you used in Postgres are possible, using
pl/sql. However, I don't think you can execute pl/sql using tdbc::odbc.

In Excel there is an all-in-one-formula: NetworkDays()
which I currently use. But I would prefer a Tcl solution.

Harm

Alexandre Ferrieux

unread,
Feb 20, 2012, 9:21:36 AM2/20/12
to
I would simply iterate from starting to ending epoch-seconds (at
midday to avoid DST effects), incrementing by 86400, and use [clock
format] in the loop to extract the weekday to shun Sat+Sun, and an
externally provided array containing holidays.

-Alex
0 new messages