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

Calculate a date that is "X" days from a known Date Field and excludes weekends

Hi,

I am working on a database which stores a start date, and a duration, the output required is when the sum start date and duration excl weekends i.e. if the startdate was the 30/10/13 and the duration is 7, the calculated date should equal 07/11/13.

I have attached a sample DB with fields / form.

Thanks in advance.

Nick.
Attached Files
File Type: zip Database4.zip (25.3 KB, 163 views)
Oct 30 '13 #1
4 2919
zmbd
5,501 Expert Mod 4TB
Basically you need to calculate business days, yes?
HowTo: Calculate business days - pure SQL approach.
Is one such method that does not involve VBA

Here are some thread here on Bytes.com along the same topic:
Google: Bytes.com "business days"

Then there's the goodole microsoft approach... this is for ACC 2007; however, it should work for ACC 2010: Counting the Number of Working Days in Access 2007

If these don't pan out let us know in detail why, post your code (formatted using the [CODE/] format) and/or the SQL (also with the [CODE/] format).

Also, please note: Most of the Experts may not be able to download attachments - especially if they are on file storage sites. This is due mainly to their company IT guidlines - or in my case, an actual block. It is prefered therefore, to have the question clearly stated, error messages posted in full, etc...
Oct 30 '13 #2
neelsfer
547 512MB
i use this code in a module, i got from the net and it is adapted to my start and end dates, to calculate weekdays, excluding weekends
It works fine for me
i call it in a query like this
Expand|Select|Wrap|Line Numbers
  1. WeekDays: Weekdays([OrderDate],[DateReceive])
Expand|Select|Wrap|Line Numbers
  1. Public Function Weekdays(ByRef OrderDate As Date, _
  2.     ByRef receivedate As Date _
  3.     ) As Integer
  4.     ' Returns the number of weekdays in the period from orderdate
  5.     ' to receivedate inclusive. Returns -1 if an error occurs.
  6.     ' If your weekend days do not include Saturday and Sunday and
  7.     ' do not total two per week in number, this function will
  8.     ' require modification.
  9.     On Error GoTo Weekdays_Error
  10.  
  11.     ' The number of weekend days per week.
  12.     Const ncNumberOfWeekendDays As Integer = 2
  13.  
  14.     ' The number of days inclusive.
  15.     Dim varDays As Variant
  16.  
  17.     ' The number of weekend days.
  18.     Dim varWeekendDays As Variant
  19.  
  20.     ' Temporary storage for datetime.
  21.     Dim dtmX As Date
  22.  
  23.     ' If the end date is earlier, swap the dates.
  24.     If receivedate < OrderDate Then
  25.         dtmX = receivedate
  26.         OrderDate = receivedate
  27.         receivedate = dtmX
  28.     End If
  29.  
  30.     ' Calculate the number of days inclusive (+ 1 is to add back orderdate).
  31.     varDays = DateDiff(Interval:="d", _
  32.         date1:=OrderDate, _
  33.         date2:=receivedate) + 1
  34.  
  35.     ' Calculate the number of weekend days.
  36.     varWeekendDays = (DateDiff(Interval:="ww", _
  37.         date1:=OrderDate, _
  38.         date2:=receivedate) _
  39.         * ncNumberOfWeekendDays) _
  40.         + IIf(DatePart(Interval:="w", _
  41.         Date:=OrderDate) = vbSunday, 1, 0) _
  42.         + IIf(DatePart(Interval:="w", _
  43.         Date:=receivedate) = vbSaturday, 1, 0)
  44.  
  45.     ' Calculate the number of weekdays.
  46.     Weekdays = (varDays - varWeekendDays)
  47.  
  48. Weekdays_Exit:
  49.     Exit Function
  50.  
  51. Weekdays_Error:
  52.     Weekdays = -1
  53.     MsgBox "Error " & Err.Number & ": " & Err.Description, _
  54.         vbCritical, "Weekdays"
  55.     Resume Weekdays_Exit
Oct 30 '13 #3
Thanks for the replies, the solutions posted both use a 'start date' and a known 'finish date'. The fields I am working with is just the 'start date' and 'duration'. I'm not sure how to adapt the code above so that it does what I need it t.

I will try to explain my requirements:

The fields in the db are:
ProgrammedStartDate - this is the start date (format dd/mm/yy)
ProgrammedDuration - this is the number of business days which need to be added to the above (& excludes Saturdays and Sundays / holidays).
(both of the above are entered by the user)

CalFinishDate - is the output I need help with and stored in the same table. If I was using Excel, I would use the =WORKDAY.INTL(A1,7,1) formula (where A1 = 30/10/13) will produce 08/11/13. It is this which I need in to reproduce in Access - however unable to with my limited knowledge.
Oct 30 '13 #4
zmbd
5,501 Expert Mod 4TB
What I would do is:
1) using the dateadd() function add the duration to my start date.
2) using one of the methods given in my or Neelsfer's posting, use the start date and the calculated date from (1) as the initial input to the methods.
2a) if the number of days returned is the same as your duration then you are done.
2b) if the number of days returned are less than your duration, add the difference to the date calculated in (1) and repeat (2) until (2a) is true.
3) Return the results
3a) start date as given in the data set
3b) end data as calculated from (2)
Oct 31 '13 #5

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

Similar topics

38
by: | last post by:
I have a script... ----- <SCRIPT language="JavaScript" type="text/javascript"> <!-- function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this = makeArray.arguments; } ...
3
by: www.ttdown.com | last post by:
Each day a user is supposed to import a list of information into a database table. The user only has 30 days to import this information. After 30 days the information is lost. I need to be able...
9
by: mistral | last post by:
Need help to remove list of days from date script. Need format "June 07, 2006" <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Get today's current date. var now = new Date();
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...
8
by: libsfan01 | last post by:
how can i use regular expressions to ensure a mysql format date entry in a text field? thanks marc
2
by: Drum2001 | last post by:
Hello, I am having isues with the following: I have two forms, a MAIN FORM with a SUB FORM: Within the MAIN FORM, I have an unbound textbox (Date Format) and a command button. Onload, the...
2
by: favor08 | last post by:
7/19/2007 12:46:30 am. is in a field called CmplteDte. It is a date stamp of when the user completed the item. I need the time for a report but for a form that the supervisors use to QA the previous...
5
by: cptuser | last post by:
Hi, I'm trying to subtract 6 days from a date in a url parameter (date_param). For example, "http://localhost/somepage?date_param=16/08/07". This is the code that I have, but it's giving the...
3
by: Cyprus106 | last post by:
I can't seem to get a reliable function that grabs the actual date 30 days in the future. Adding +30 to the date() function doesn't seem to compensate for if the next month has less than the +30...
1
by: fwaisfeld | last post by:
Hello i am in need of some help with this JS function. I am using a script which gets Today's date, and i am looking to get Tomorrow's date. I need some help. I will show you what i have and please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.