Workday count between [Startdate] & [Enddate]

  • Thread starter Thread starter Pete
  • Start date Start date
P

Pete

Hi

Trying to count the number of Workdays only between 2 dates. [Startdate] &
[Enddate] can anyone help please.

Cheers
Sarah
 
Hi

Trying to count the number of Workdays only between 2 dates. [Startdate] &
[Enddate] can anyone help please.

Cheers
Sarah


SELECT MastrPhoneStatsTbl.DATE, Format([DATE],"dddd") AS Expr1
FROM MastrPhoneStatsTbl
GROUP BY MastrPhoneStatsTbl.DATE, Format([DATE],"dddd")
HAVING (((MastrPhoneStatsTbl.DATE) Between #12/1/2006# And
#12/30/2007#) AND ((Format([DATE],"dddd")) In
('Monday','Tuesday','Wednesday','Thursday','Friday')));


That will get you every date and day (Mon-Fri) in between 12/1/2006
and 12/31/2007 in the table "MastrPhoneStats" having the field name
"DATE".

Just Sub your table names and fields in
 
Pete said:
Hi

Trying to count the number of Workdays only between 2 dates. [Startdate] &
[Enddate] can anyone help please.

Cheers
Sarah

Using the result from:

http://groups.google.com/group/comp.databases.ms-access/msg/548d33651b087c05

qryNumberOfWeekdays:
SELECT IIf([Startdate] IS NOT NULL AND [Enddate] IS NOT NULL,
DateDiff("d", [Startdate], [Enddate]) + 1 -
CountWeekendDays([Startdate],[Enddate]), Null) As NumberOfWeekdays FROM
MyTable;

Example:

MyTable
Startdate Date/Time
Enddate Date/Time
Startdate Enddate
2/25/2007 3/31/2007
Null Null

!qryNumberOfWeekdays:
NumberOfWeekdays
25
Null

Note that this does not account for holidays.

James A. Fortune
(e-mail address removed)
 
Hi

Trying to count the number of Workdays only between 2 dates. [Startdate] &
[Enddate] can anyone help please.

Cheers
Sarah
One way of doing this is to have a calendar table and a
holidays table. This is school days, but it could just as
easily be business or work days. Omit the check constraints and
just enter them in table design as validation rules. Holiday
can be in the calendar table rather than in a separate holidays
table.

CREATE TABLE SchoolCalendar
(class_date DATETIME NOT NULL PRIMARY KEY,
weekday_nbr INTEGER NOT NULL,
school_day INTEGER DEFAULT 1 NOT NULL,
holiday INTEGER DEFAULT 0 NOT NULL,
CONSTRAINT ck_schoolcalendar_weekday_nbr
CHECK weekday_nbr BETWEEN 1 AND 7,
CONSTRAINT ck_schoolcalendar_school_day
CHECK school_day IN (0,1),
CONSTRAINT ck_schoolcalendar_holiday
CHECK holiday IN (0,1))

After calendar is filled, make Saturday and Sunday as non-
school days.

UPDATE SchoolCalendar
SET SchoolCalendar.school_day = 0
WHERE (((SchoolCalendar.weekday_nbr) = 1
OR (SchoolCalendar.weekday_nbr) = 7));

CREATE TABLE Holidays
(holiday DATETIME NOT NULL PRIMARY KEY,
holiday_name VARCHAR (30) NOT NULL)

Query: Count class days in calendar period
-------------------------------------------
PARAMETERS [Enter start date:] DateTime, [Enter end date:]
DateTime;
SELECT COUNT(* )
FROM SchoolCalendar
WHERE (((SchoolCalendar.class_date) BETWEEN [Enter start
date:] AND [Enter end date:])
AND SchoolCalendar.school_day = 1
AND NOT EXISTS (SELECT Holidays.holiday
FROM Holidays
WHERE Holidays.holiday =
SchoolCalendar.class_date);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top