473,765 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Workday Date Calculations

Hi all

I'm trying to calculate the number of days (or workdays) between 2 given
dates that do not include weekend days or public holidays
(public holidays are user defined from a dbase, have a start date & an end
date & may span a weekend)
If a start date (workday) & an end date (workday) are on the same day then
the number of workdays will equal zero

Some eg's.

Start Date - 2-Dec-04 (Thurs)
End date 2-Dec-04 (Thurs)
No of working days = 0

Start Date - 2-Dec-04 (Thurs)
End date 3-Dec-04 (Fri)
No of working days = 1

Start Date - 2-Dec-04 (Thurs)
End date - 10-Dec-04 (Fri)
No of working days = 6 (8 total days minus 2 weekend days)

Start Date - 2-Dec-04 (Thurs)
End date - 22-Dec-04 (Wed)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 12 (20 total days minus 6 weekend days minus only 2 of
the Public Holiday days as 2 fell on a weekend)

Start Date - 2-Dec-04 (Thurs)
End date - 17-Dec-04 (Fri)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 10 (15 total days minus 4 weekend days minus only 1 of
the Public Holiday days as the End date fell on the 1st day of the Public
Holday)

I've been experimenting with timespans & datediff but just can't seem to get
it off the ground

Has anyone done something similar or could point me in the right direction ?

Regards
Wayne

Nov 21 '05 #1
1 6134
Wayne,

Really fun stuff, I assume (hope for you) you get a lot of better sollutions
than this.

This is quickly made, when you go in the direction of the timespan, know
than that it has a limited value.

Hollidays are not in the Framework. However they are in office.

I made a table with one holliday and because this year chrismass as well as
newyear are on saterday sunday I took tomorrow as a holliday in this sample

\\\start time sample is 2004, dec, 2
Public Class Hello
Public Shared Sub main()
Dim DateToReach As DateTime = New DateTime(2005, 1, 1)
Dim hollidays(0) As DateTime
hollidays(0) = New DateTime(2004, 12, 3) 'just for the test
Dim count As Integer
Dim Testdate As DateTime = Now
Do Until Testdate.Date = DateToReach.Dat e
If Testdate.DayOfW eek <> DayOfWeek.Sunda y AndAlso _
Testdate.DayOfW eek <> DayOfWeek.Satur day Then
Dim holliday As Boolean = False
For Each td As Date In hollidays
If Testdate.Date = td.Date Then
holliday = True
Exit For
End If
Next
If holliday = False Then
count += 1
End If
End If
Testdate = Testdate.AddDay s(1)
Loop
MessageBox.Show (count.ToString )
End Sub
///

I hope this helps something?

Cor

"Wayne" <wg****@hotmail .com>
Hi all

I'm trying to calculate the number of days (or workdays) between 2 given
dates that do not include weekend days or public holidays
(public holidays are user defined from a dbase, have a start date & an end
date & may span a weekend)
If a start date (workday) & an end date (workday) are on the same day then
the number of workdays will equal zero

Some eg's.

Start Date - 2-Dec-04 (Thurs)
End date 2-Dec-04 (Thurs)
No of working days = 0

Start Date - 2-Dec-04 (Thurs)
End date 3-Dec-04 (Fri)
No of working days = 1

Start Date - 2-Dec-04 (Thurs)
End date - 10-Dec-04 (Fri)
No of working days = 6 (8 total days minus 2 weekend days)

Start Date - 2-Dec-04 (Thurs)
End date - 22-Dec-04 (Wed)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 12 (20 total days minus 6 weekend days minus only 2
of
the Public Holiday days as 2 fell on a weekend)

Start Date - 2-Dec-04 (Thurs)
End date - 17-Dec-04 (Fri)
Public Holiday Start Date - 17-Dec-04 (Fri)
Public Holiday End Date - 20-Dec-04 (Mon)
No of working days = 10 (15 total days minus 4 weekend days minus only 1
of
the Public Holiday days as the End date fell on the 1st day of the Public
Holday)

I've been experimenting with timespans & datediff but just can't seem to
get
it off the ground

Has anyone done something similar or could point me in the right direction
?

Regards
Wayne

Nov 21 '05 #2

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

Similar topics

13
9304
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and three dropdow boxes for hours, minutes, and AM/PM. All of these need to be considered together and converted to one Unix Timestamp and then inserted to the MYSQL date field. The type of field is INT (11) so that I can instead of the standard...
2
5219
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
11
4675
by: lduperval | last post by:
Hi, I`m trying to do date calculations in three types of time zones: local, GMT and specified. The issue I am facing is that I need to be able to specify a date in the proper time zone, and I`m having a heck of a time doing so. I have created a form where I use drop downs do specify year, month, date, hour, minute and seconds. When the form is loaded, the dropdowns have to display the proper values for the current time zone type. This
2
7334
by: Joe Jax | last post by:
I have some date calculations that add a time span to a date. The problem is, when I add a time span that is a whole number of days to a date, the result can be +/- 1 hour due to daylight savings. Is there anyway to disable this?
1
1967
by: SirPoonga | last post by:
I need a workday function like excel has. I found vba code for access to dot he task. I want to try and convert it. One of the funcitosn has the parameter "Optional dtmDate as Date = 0". I need to convert that to something asp.net recognizes. I haven;t used the DateTime in asp.net too much.
3
2719
by: Glencannon4424 via AccessMonster.com | last post by:
Hello, I have what I believe amounts to a Date Serial issue. I have the following columns in my table: Hire-Date Hire-Year WTD-RATE Wks-in-Yr
8
2112
by: Charlie Brookhart | last post by:
I am creating a program that involves having to find the difference between two dates and converting it to a number to be used for calculations. The problem is that the way it is setup, VB is not doing anything with the dates that I have selected. I hope that someone here can help me figure out why it is not working what I have to do to make it work. This the code I have for the date calculations. txtNumberOfDays.text =...
3
4327
by: buddyr | last post by:
Hello, I have 3 fields dateout, datein, TurnAroundNumber(number). I used this code in module: Function GetDateOut(dDate As Date, Span As Integer) As Date Dim j As Integer, i As Integer, dtStart dtStart = dDate For j = 1 To Span dtStart = dtStart + 1 Do While Weekday(dtStart) = 1 Or Weekday(dtStart) = 7 dtStart = dtStart + 1
17
15423
by: trixxnixon | last post by:
i have a form with these fields Priority level: urgent critical standard business days: 1, 3, 15 date submitted: current date due date:
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.