473,382 Members | 1,225 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,382 software developers and data experts.

Question regarding posted algorithm for calculating dates that do not fall on a weeke

USTRAGNU1
The post can be found here:

https://bytes.com/topic/access/answers/954598-calculate-date-but-do-not-count-weekends-holidays

Here is the algorithm by Adezii I am referring to:

[code]..
1.Public Function fCalcWorkDays2(dteStartDate As Date, lngNumOfDays As Long)
2. Dim lngCount As Long
3. Dim lngCtr As Long
4. Dim dteDate As Date
5.
6. lngCount = 0
7. lngCtr = 1
8.
9. Debug.Print "Date", "Day Count", "Weekday"
10.
11. Do
12. dteDate = DateAdd("d", lngCtr, dteStartDate)
13. Select Case Weekday(dteDate)
14. Case 7, 1 'Saturday and Sunday, do nothing
15. Case Else 'Monday thru Friday, OK
16. 'Is it a Holiday as posted in tblHolidays?
17. If DCount("*", "tblHolidays", "[Date] = #" & dteDate & "#") < 1 Then 'NOT Holiday
18. lngCount = lngCount + 1 'Increment Counter
19. Debug.Print dteDate, lngCount, Weekday(dteDate)
20. End If
21. End Select
22. lngCtr = lngCtr + 1
23. Loop While lngCount < lngNumOfDays
24. fCalcWorkDays2 = dteDate
25. End Function]
[Code/]..

I work for the Air Force and I am trying to create function that will do this very thing, but mine is adding too many days. Adezii's function looks much cleaner, but I do not understand a couple of items.

1. Would anyone be able to explain what is meant by line 17:

If DCount("*", "tblHolidays", "[Date] = #" & dteDate & "#") < 1 ?

Does this mean his dates in tblHolidays are enclosed in pound signs, or is that the way it needs to be written in the function?

2. I don't quite understand how typing Case 7,1 on line 14 tells access to ignore Saturday and Sunday. Can someone explain that?

If you have questions or require additional information, please email me.

Thanks!

Mike Munitz
Mar 16 '17 #1
4 942
PhilOfWalton
1,430 Expert 1GB
In general, a date needs a hash mark either side of it to tell Access it is a date. So today would be #16 March 2017#.

I guess you are American so your dates are even more illogical than English dates. We would write 16/3/2017 and I guess you would write 3/16/2017. Unless there are hash marks which you incorrectly call pounds signs (£ is a pound sign) then access would consider 3/16/2017 as a division sum. (3 divided by 16 divided by 2017)

In Answer to your second question, the weekday function returns a number from 1 to 7, 1 being Sunday, 2 Monday etc and 7 = Saturday.
So it's saying if Weekday is 1 or 7 (Sunday or Saturday) do whatever follows... but nothing follows, so then we go on to
Case Else (Not Sunday or Saturday) do whatever follows, and there we start doing calculations about holidays.

Hope that helps.

Phil
Mar 16 '17 #2
Hi Phil,

Yes I am American, and yes our date formats can be batty to deal with, and yes your explanations answer my questions.

I too am familiar with the term hash mark. However, I disagree with your overall assessment:

pound sign
/ˈpound ˌsīn/
noun
noun: pound sign; plural noun: pound signs
1. North American - the sign #, representing a pound as a unit of weight or mass, or as represented on a telephone keypad or computer keyboard.

2. the sign £, representing a British pound sterling.

Thank you for the quick reply Phil!

MikeOfMurrica
Mar 16 '17 #3
PhilOfWalton
1,430 Expert 1GB
Ah, Mike, I live & learn.

We use Lb. for pounds weight from the Latin Libra - Scales (& also a star constellation and sign of the zodiac)

Phil
Mar 17 '17 #4
Phil,

I am a Libra...coincidence?

Have a great weekend!

Mike
Mar 17 '17 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Francis Lavoie | last post by:
Hello I have some questions regarding webframework, I must say that I quite lost and these questions are basicly to help me understand the way it work. I have some knowledge with PHP and JSP....
3
by: Samuel | last post by:
I wrote a very simple httpmodule and tried to compile it with no success. This is my code: ============== Imports System Imports System.Web Imports Microsoft.VisualBasic NameSpace...
7
by: Squignibbler | last post by:
Hi all, I have a question regarding the C++ programming language regarding the nature of the relationship between pointers and arrays. If the statement MyArray is functionally identical to...
2
by: Arun Prasath | last post by:
Hi all, I have the following question regd pointer typecasting. Is the following type of pointer typecasting valid? #define ALLOC(type,num) ((type *)malloc(sizeof(type)*num)) /*begin...
2
by: ben | last post by:
hello, i'm following an algorithm book and am stuck on an early excersise in it, not because of the c programming side of it or even the algorithm side of it, i don't think, but because of maths....
2
by: Dean R. Henderson | last post by:
For an ASP.NET web application, is there a way for one session (with appropriate security authorization) to set a HttpSessionState variable to point to another session and execute the Abandon...
1
by: Terrance | last post by:
I was wondering if someone can help me with my question regarding the configuration system functionality in the .NET Framework 2.0 for VB. My question is, if I have a application configuration...
5
by: archana | last post by:
Hi all, I am using timer to do some functionality on user specified time. I am using system.timers.timer class and its timer to do this functionality. What i am doing is i set autoreset to...
4
by: Benny Van | last post by:
Hi all! I have a question regarding a windows operating system function: I was asked to write a small program for a homework to display the user name and computer name and the system time out to a...
8
by: Goran | last post by:
Hi all, I have a question regarding operator <<. A lib of mine contains a class with an overloaded operator << as NON- class member. This would look like: #include <iostream> #include...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.