473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Date Problem - How to identify working days only

I need to write a report in which one part shows a count of how many
total records fall within the working days (Monday - Friday) inside of a
(prompted) given date range, in a particular geographical region.

I have written a query which prompts the user for the start and end
dates. It also filters for entries which pertain to the particular
geographical region.

I'm not sure where to go from here.

How do I filter the results to show only the records within the prompted
date range which fall within the Work Week (ie: Monday - Friday)? (
ie: I need to somehow filter out Saturday and Sunday days/dates within
the prompted date range)

Once I have the query filtered to show only records which fall within
the required date range, region, and only within the (Mon-Fri) Work
Week, I then need a simple count of how many records there are. How do
I achieve this result?

Can anyone help me with suggested coding, and structure in the query
grid so as to accomplish this result?

BlackFireNova

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
5 14859
You should be able to use the Weekday function to eliminate records that occur on certain
days of the week. You may need to adjust for the first day of the week in your locality.

Weekday(#10/23/2003#) = 5 for Thursday, to eliminate weekends you would not want
Weekday([DateField]) to be 1 or 7. You would set this to be a calculated field in the
query.

In the Query design grid
Field: NoWeekends:Weekday([TableName].[DateField])
Criteria: <>1 And <>7

You could uncheck the Show box unless you need the numbers 2-6 (for Mon - Fri) in the
output of the query for something else. It will filter on this even if the value doesn't
show in the output.

Question, if you are only working on Mon through Fri, how did records get in on Sat and
Sun? If there aren't any, you may not need to filter them out. If they are there, then
weren't Sat and Sun work days also?

The syntax for the Weekday function is Weekday(date, [firstdayofweek])

--
Wayne Morgan
Microsoft Access MVP
"BlackFireNova" <BF*****************@myrealbox.com> wrote in message
news:3f*********************@news.frii.net...
I need to write a report in which one part shows a count of how many
total records fall within the working days (Monday - Friday) inside of a
(prompted) given date range, in a particular geographical region.

I have written a query which prompts the user for the start and end
dates. It also filters for entries which pertain to the particular
geographical region.

I'm not sure where to go from here.

How do I filter the results to show only the records within the prompted
date range which fall within the Work Week (ie: Monday - Friday)? (
ie: I need to somehow filter out Saturday and Sunday days/dates within
the prompted date range)

Once I have the query filtered to show only records which fall within
the required date range, region, and only within the (Mon-Fri) Work
Week, I then need a simple count of how many records there are. How do
I achieve this result?

Can anyone help me with suggested coding, and structure in the query
grid so as to accomplish this result?

BlackFireNova

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #2
For the second part, this example should work to count them. Adjust for your date limits.

SELECT Count(1) AS CountMe
FROM Table2
WHERE (((Table2.Field2) Between #1/1/2003# And Date()) AND
((Weekday([Table2].[Field2]))<>1 And (Weekday([Table2].[Field2]))<>7));
--
Wayne Morgan
Microsoft Access MVP
Nov 12 '05 #3
Wayne:

I should have been a bit more specific.

In the date range, I need to identify the number of records which fall
in a given range (shown below). The range must be Work Days counted,
not including weekends.

Referrals not yet formally assessed (for the past month, or within the
date range specified - Usually 1 month)
5 or less(Working Days)
5-10 (Working Days)
10-21 (Working Days)
21 (Working Days) or older.

I have to somehow set up a series of calculations which counts from the
first date in the prompt, to the next division (5 or less), then
discounts weekends. Then same from 5-10 days, discounting weekend days,
etc., for the range.

BFN

BlackFireNova

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #4
The query in my second reply will do this. You may need to use a form to have the user
input a date range, then click a button to start counting. In the code behind the button,
break the date range up into however many date periods you want within the entered range
and use them in the query to return the results.

SELECT Count(1) AS CountMe
FROM Table2
WHERE (((Table2.Field2) Between #1/1/2003# And Date()) AND
((Weekday([Table2].[Field2]))<>1 And (Weekday([Table2].[Field2]))<>7));

--
Wayne Morgan
Microsoft Access MVP
"BlackFireNova" <BF*****************@myrealbox.com> wrote in message
news:3f*********************@news.frii.net...
Wayne:

I should have been a bit more specific.

In the date range, I need to identify the number of records which fall
in a given range (shown below). The range must be Work Days counted,
not including weekends.

Referrals not yet formally assessed (for the past month, or within the
date range specified - Usually 1 month)
5 or less(Working Days)
5-10 (Working Days)
10-21 (Working Days)
21 (Working Days) or older.

I have to somehow set up a series of calculations which counts from the
first date in the prompt, to the next division (5 or less), then
discounts weekends. Then same from 5-10 days, discounting weekend days,
etc., for the range.

BFN

BlackFireNova

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 12 '05 #5
BlackFireNova <BF*****************@myrealbox.com> wrote in
news:3f*********************@news.frii.net:
Wayne:

I should have been a bit more specific.

In the date range, I need to identify the number of records
which fall in a given range (shown below). The range must be
Work Days counted, not including weekends.

Referrals not yet formally assessed (for the past month, or
within the date range specified - Usually 1 month)
5 or less(Working Days)
5-10 (Working Days)
10-21 (Working Days)
21 (Working Days) or older.

You may want to use a calendar table. This version works back from
a given Finish date till the number of days you input has been
input.

You first need to create table calendar with two fields, bookeddate
and daynumber.

'------------------------
Public Sub setCalendar()
Dim dDate As Date
Dim strDays As String
Dim i As Integer
Dim j As Integer
Dim Days As Integer

dDate = Date
strDays = InputBox("Enter the number of days")
If strDays = "" Then GoTo exit_setDateRange
Days = CInt(strDays)
DoCmd.RunSQL "DELETE * from calendar"
DoCmd.RunSQL "Insert into calendar " & _
"(BookedDate,daynumber) " & _
"VALUES (#" & dDate & "# ," & j & ");"

For i = 1 To Days
If WeekDay(dDate - i, 1) <> 1 & _
And WeekDay(dDate - i, 1) <> 7 Then
j = j + 1
End If
DoCmd.RunSQL "Insert into calendar " & _
"(BookedDate,daynumber) " & _
"VALUES (#" & (dDate - i) & "# ," & j & ");"
Next i
exit_setDateRange:
Exit Sub
End Sub
'----------------------

This will give you a list of dates and the number of workdays
between then and today.

BookedDate daynumber
Friday, October 10, 2003 10
Saturday, October 11, 2003 9
Sunday, October 12, 2003 9
Monday, October 13, 2003 9
Tuesday, October 14, 2003 8
Wednesday, October 15, 2003 7
Thursday, October 16, 2003 6
Friday, October 17, 2003 5
Saturday, October 18, 2003 4
Sunday, October 19, 2003 4
Monday, October 20, 2003 4
Tuesday, October 21, 2003 3
Wednesday, October 22, 2003 2
Thursday, October 23, 2003 1
Friday, October 24, 2003 0
I have to somehow set up a series of calculations which counts
from the first date in the prompt, to the next division (5 or
less), then discounts weekends. Then same from 5-10 days,
discounting weekend days, etc., for the range.

BFN

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Simon Dean | last post by:
Probably being a little thick here, but when you subtract one date away from another, how do you convert the resultant value into a number of days... I guess I could easily / 60 / 60 / 24... but...
3
by: Jason Huang | last post by:
Hi, In our C# Windows Form application, we are using the SQL Server 2000 as the database server. The Database table MyTable has a field RegistrationDate which represents the Date a client comes...
0
by: kumarkanth | last post by:
My question is how do I manipulate the procedure to calculate cut-off date with in working days and it should skip weekends and holidays? I have holiday table to determine holidays Table Name :...
29
by: Santiagoa | last post by:
If I set up a task table with an Date_assigned and a number of days to complete the task I calculate the end_date field by using the code below I found in this forum How ever when I enter the...
2
by: Maninder Karir | last post by:
Hi, Im trying to work out how to return a date based on addition of working days only. On the userform the user enters the date using dtpicker. They then have the option to add 5, 10 or 15...
1
by: almurph | last post by:
Hi, I have a trickly little problem that I hope you can help me with. I need to add *working* days to a DateTime object of the format: yyyy/MM/ dd For example: say I have a timestamp of the...
1
by: KasSamrari | last post by:
Hello, I am working on an access dB where the release date is only populated once the products have been released otherwise remain blank. I can calculate the working days if the MfgDate and...
3
Jerry Maiapu
by: Jerry Maiapu | last post by:
Hi Scott Prince, Since this dean is not interested I need to do the same as Dean is trying to do. Since Dean has not replied would you mind to show me how to do this: You'll have to open this into...
2
by: Organised Angel | last post by:
Hi everyone I'm doing a project at work and I'm managing most of it fine apart from one section where I need to calculate a due date. The due date is 5 working days after the date entered. I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.