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

Dates and Holidays. I need direction

Back again, thirsting for knowlege. :)

http://www.thescripts.com/forum/show...76#post2314976
Was my last thread. I am still working on the same project, but a different stage.

I now have my form, subtracting the leave date, and return date. The result is then sent to my "DaysGone" box and then its value is multiplied by 8 (8 hours in a workday) and then send to "HoursGone" The first step was getting it all to work, and it works great now, thanks to help from the community, mainly Mary.

My Question now, is How do I figure in weekends? And Possibly Holidays.

i.e. A employee leaves on wednesday and returns the followoing wednesday, he would be missing 7 days. However, since weekends do not count, the employee has only missed 5 days of work.

I am not expecting anyone to hand me the code (though it would help ;) ) If there is a good place to start researching this, just point me in the right direction, is all I ask.

Thank you
Jan 17 '07 #1
17 3986
ADezii
8,834 Expert 8TB
Back again, thirsting for knowlege. :)

http://www.thescripts.com/forum/show...76#post2314976
Was my last thread. I am still working on the same project, but a different stage.

I now have my form, subtracting the leave date, and return date. The result is then sent to my "DaysGone" box and then its value is multiplied by 8 (8 hours in a workday) and then send to "HoursGone" The first step was getting it all to work, and it works great now, thanks to help from the community, mainly Mary.

My Question now, is How do I figure in weekends? And Possibly Holidays.

i.e. A employee leaves on wednesday and returns the followoing wednesday, he would be missing 7 days. However, since weekends do not count, the employee has only missed 5 days of work.

I am not expecting anyone to hand me the code (though it would help ;) ) If there is a good place to start researching this, just point me in the right direction, is all I ask.

Thank you
Expand|Select|Wrap|Line Numbers
  1. 'Unless you modify the firstdayofweek Parameter to this Function:
  2. 'To see if a Date falls on a Saturday or Sunday:
  3. If Weekday([YourDate]) = 7 Or If Weekday([YourDate]) = 1 Then
  4.     'the Date is on a Saturday (7) or Sunday (1)
  5.     'process code here
  6. End If
  7.  
  8. 'Holidays would have to be pre-determined and filtered out.
Jan 18 '07 #2
NeoPa
32,556 Expert Mod 16PB
Just to fill in with some more explanation :
Holidays is one of those often asked questions that seem to some, to be obviously very easy. Some need to be disabused! It is a very complicated area as it does not fit very well into the concepts of an RDBMS. There are threads in TSDN which go into this in more detail and do resolve the issue (mostly), but they are hard work and require extra maintenance.
Another similarly tough question that some feel should be very easy, is numbering lines returned from a query. Again, there are threads that explain how, but unless you have a hardy constitution, you don't want to go there.
Jan 18 '07 #3
Expand|Select|Wrap|Line Numbers
  1. 'Unless you modify the firstdayofweek Parameter to this Function:
  2. 'To see if a Date falls on a Saturday or Sunday:
  3. If Weekday([YourDate]) = 7 Or If Weekday([YourDate]) = 1 Then
  4.     'the Date is on a Saturday (7) or Sunday (1)
  5.     'process code here
  6. End If
  7.  
  8. 'Holidays would have to be pre-determined and filtered out.

So, where you have the "YourDate", I would switch with "LeaveDate" and "ReturnDate" Those being the fields that hold the dates in my app.

If Weekday([LeaveDate]) = 7 Or If Weekday([LeaveDate]) = 1Then
???? Week = 5 days? Then I would have to send 5 days plus any other days from the following week, to my "DaysGone" field. Something isnt making sense....could you by chance give me a little more detail?
Jan 18 '07 #4
I have spoke with the HR department, about the holidays and they said that, they could manually do everything else, but if I could get the weekends to subtract from my total number of days. Like every 7 days, then subtract 2 days or something. Either way, it makes my task a little less daunting knowing that I don't have to figure out the holidayz

Thx
Jan 18 '07 #5
NeoPa
32,556 Expert Mod 16PB
Have a look at ADezii's post again and see if you can work it out.
I'm going out now but will be back later. If you post that you still can't see why it's right then I will give a fuller explanation for you when I get back.
Jan 18 '07 #6
MMcCarthy
14,534 Expert Mod 8TB
So, where you have the "YourDate", I would switch with "LeaveDate" and "ReturnDate" Those being the fields that hold the dates in my app.

If Weekday([LeaveDate]) = 7 Or If Weekday([LeaveDate]) = 1Then
???? Week = 5 days? Then I would have to send 5 days plus any other days from the following week, to my "DaysGone" field. Something isnt making sense....could you by chance give me a little more detail?
This is simply a way of checking if a date is a saturday or a sunday. You would start at "LeaveDate" and check each date up to "ReturnDate" and add 1 for each date that wasn't a weekend day.

Mary
Jan 19 '07 #7
Killer42
8,435 Expert 8TB
I thought DateDiff had a weekdays-only option. (Or am I thinking of DateAdd...)
Jan 19 '07 #8
NeoPa
32,556 Expert Mod 16PB
I've tried the 'Weekdays' option in Access2K (I forget which function - DateAdd() I think) and it's buggy. I ended up creating my own function to do it :(
Jan 19 '07 #9
Killer42
8,435 Expert 8TB
I've tried the 'Weekdays' option in Access2K (I forget which function - DateAdd() I think) and it's buggy. I ended up creating my own function to do it :(
Oops!

Definitely another one to add to the tips and tricks.
Jan 19 '07 #10
NeoPa
32,556 Expert Mod 16PB
Oops!

Definitely another one to add to the tips and tricks.
If you like.
I'll get posting tomorrow probably.
Jan 20 '07 #11
Hi guys

I encounter the same pain at the moment in my MS Access. Can I know what is the VBA or Expression codes? Mine is similar; I have Date1 and Date2. I want to have a separate column which would count the difference of both dates (in terms of weekdays and if possible, exclude out certain days like public holidays, which would be added in manually). I’ve tried DateDiff but it didn’t work for me. At last, I used Date2-Date1 as temporary resort. Is there any other way to do this, at least counting only the weekdays?

Thanks.

Regards
Anthony

Back again, thirsting for knowlege. :)

http://www.thescripts.com/forum/show...76#post2314976
Was my last thread. I am still working on the same project, but a different stage.

I now have my form, subtracting the leave date, and return date. The result is then sent to my "DaysGone" box and then its value is multiplied by 8 (8 hours in a workday) and then send to "HoursGone" The first step was getting it all to work, and it works great now, thanks to help from the community, mainly Mary.

My Question now, is How do I figure in weekends? And Possibly Holidays.

i.e. A employee leaves on wednesday and returns the followoing wednesday, he would be missing 7 days. However, since weekends do not count, the employee has only missed 5 days of work.

I am not expecting anyone to hand me the code (though it would help ;) ) If there is a good place to start researching this, just point me in the right direction, is all I ask.

Thank you
Jan 20 '07 #12
NeoPa
32,556 Expert Mod 16PB
Oops!

Definitely another one to add to the tips and tricks.
If you like.
I'll get posting tomorrow probably.
Here it is (Function to Move (Forwards or Backwards) Through Weekdays).
Jan 21 '07 #13
Expand|Select|Wrap|Line Numbers
  1. 'MoveWD moves datThis on by the intInc weekdays.
  2. Public Function MoveWD(datThis As Date, intInc As Integer) As Date
  3.     MoveWD = datThis
  4.     For intInc = intInc To Sgn(intInc) Step -Sgn(intInc)
  5.         MoveWD = MoveWD + Sgn(intInc)
  6.         Do While (Weekday(MoveWD) Mod 7) < 2
  7.             MoveWD = MoveWD + Sgn(intInc)
  8.         Loop
  9.     Next intInc
  10. End Function
Ok, i think i have the process of this down in my head. But a few noob questions.

1. The function MoveWD(datThis As Date....etc.
What is MoveWD? Is it a form? is it a button?

2. Do I tie this function into the Calendar code, or into the field that the calendar results are put into?

I understand what the code is doing, i guess im just missing how to integrate it into my project.

Thanks yet again :)
Jan 25 '07 #14
MMcCarthy
14,534 Expert Mod 8TB
1. The function MoveWD(datThis As Date....etc.
What is MoveWD? Is it a form? is it a button?

This is just a function name. You use this name to call the function elsewhere

2. Do I tie this function into the Calendar code, or into the field that the calendar results are put into?

To call this function you would simply use ...


Me.DateFieldName = MoveWD(<Date Parameter>)

Date Parameter is whatever the variable name is that the calendar stores the date in.
Jan 25 '07 #15
NeoPa
32,556 Expert Mod 16PB
1. The function MoveWD(datThis As Date....etc.
What is MoveWD? Is it a form? is it a button?
MoveWD, as Mary says in her post, is the function itself.
2. Do I tie this function into the Calendar code, or into the field that the calendar results are put into?
Me.DateFieldName = MoveWD(<Date Parameter>)

Date Parameter is whatever the variable name is that the calendar stores the date in.
Generally you would create a new module and place it in there (unless you already had a general purpose module for such routines). Call it from your code.
Here are some more detailed steps to help :
  1. From the Access window hit Alt-F11 to open and switch to the VBA window.
  2. Select Insert / Module.
  3. In the newly created module window paste in the code.
  4. You can now call it from just about anywhere in your project - SQL; Query; VBA Code; etc.
  5. The calling code is as Mary states, except that you also need to supply an intInc parameter. This says how many weekdays forwards (+) or backwards (-) you want to go.
Jan 26 '07 #16
What do you mean by "How many days you want to go forward (+)"?

The dates that I am working with are selected in two fields. One being the leave date and the other return date. The amount of days I want go forward is based on the difference between those two fields.

Is there another bit of code i need to stick in there to patch it all together?
Jan 29 '07 #17
NeoPa
32,556 Expert Mod 16PB
What do you mean by "How many days you want to go forward (+)"?
This is saying that you put in a positive number for moving the date onwards (forwards). Conversely, if you want a number of weekdays before a given date you use a negative number of days.
The dates that I am working with are selected in two fields. One being the leave date and the other return date. The amount of days I want go forward is based on the difference between those two fields.

Is there another bit of code i need to stick in there to patch it all together?
Are you trying to say that you want to find the number of weekdays between two dates rather than add (or subtract) weekdays to (from) a given date?
Jan 29 '07 #18

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

Similar topics

1
by: StinkFinger | last post by:
All, Struggling with a query here. table name : holidays fields : holname (format varchar) holdate (format date 2004-01-01) The table is populated with all the holidays for the next 5 years....
11
by: Peter Pfeiffer | last post by:
I've written several scripts that have "while" blocks which increment a date by one day if the date does not match one of a group of dates. However, sometimes it apparently steps out out the while...
5
by: SimonC | last post by:
Help needed for a Javascript beginner. As above in the subject... i need a javascript to run this, but not in the form of a web-page. I want to calculate it between 2 fields in a database that...
24
by: PromisedOyster | last post by:
Is there a way that I can get a resultset that contains unique dates in a given date range without the need to have a temporary table and a cursor? perhaps something like: declare @start_date...
12
by: Dixie | last post by:
I am trying to calculate the number of workdays between two dates with regards to holidays as well. I have used Arvin Meyer's code on the Access Web, but as I am in Australia and my date format is...
2
by: MLH | last post by:
With a table of holidays and A97's date fn's - how best to count weekends and holidays between two dates? My holiday table has 4 fields. I will be adding records to it each year as info becomes...
7
by: arbpen | last post by:
I'm sure there's a simple way to do this, but I can't seem to find it: If today is after February 1st and before February 15th then do valentines elseif today is after March 1st and before March...
2
by: Dan2kx | last post by:
Hello i have a holiday table with staff ID's and single entry dates (for holidays skipping weekends) I need a crosstab to show the dates as the column, and the staff id as the row, and count...
9
by: Scholar81 | last post by:
Hello, I am a novice Access developer and my boss asked me to build a database and I said yes. Now I realized the bite is way too big and I'm trying not to choke ;-) And what's worse, he does...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.