Hi
I been away for sometime. Pls help me with my new problem
i need to do a leave calculation using a text box.
I have a start date (date format) and number of days(number).
The calculation i can do is
lastdate=datead d("d",-1,[start date]+[number of days])
this gives the difference, but i need to minus the weekends from the total
I tried using "w" instead of "d" but no use
pls help me
Rj
2 12165
For obvious reasons, this is not something that can be done with a line or two of code! I picked this function up somewhere in the past. Sad to say, I don't know who to credit for it!
In the objects dialog box, click on Modules
Click on New
Copy and Paste this code in the module - '**********************************************************
-
'Declarations section of the module
-
'**********************************************************
-
-
Option Explicit
-
-
'==========================================================
-
' The DateAddW() function provides a workday substitute
-
' for DateAdd("w", number, date). This function performs
-
' error checking and ignores fractional Interval values.
-
'==========================================================
-
Function DateAddW (ByVal TheDate, ByVal Interval)
-
-
Dim Weeks As Long, OddDays As Long, Temp As String
-
-
If VarType(TheDate) <> 7 Or VarType(Interval) < 2 Or _
-
VarType(Interval) > 5 Then
-
DateAddW = TheDate
-
ElseIf Interval = 0 Then
-
DateAddW = TheDate
-
ElseIf Interval > 0 Then
-
Interval = Int(Interval)
-
-
' Make sure TheDate is a workday (round down).
-
-
Temp = Format(TheDate, "ddd")
-
If Temp = "Sun" Then
-
TheDate = TheDate - 2
-
ElseIf Temp = "Sat" Then
-
TheDate = TheDate - 1
-
End If
-
-
' Calculate Weeks and OddDays.
-
-
Weeks = Int(Interval / 5)
-
OddDays = Interval - (Weeks * 5)
-
TheDate = TheDate + (Weeks * 7)
-
-
' Take OddDays weekend into account.
-
-
If (DatePart("w", TheDate) + OddDays) > 6 Then
-
TheDate = TheDate + OddDays + 2
-
Else
-
TheDate = TheDate + OddDays
-
End If
-
-
DateAddW = TheDate
-
Else ' Interval is < 0
-
Interval = Int(-Interval) ' Make positive & subtract later.
-
-
' Make sure TheDate is a workday (round up).
-
-
Temp = Format(TheDate, "ddd")
-
If Temp = "Sun" Then
-
TheDate = TheDate + 1
-
ElseIf Temp = "Sat" Then
-
TheDate = TheDate + 2
-
End If
-
-
' Calculate Weeks and OddDays.
-
-
Weeks = Int(Interval / 5)
-
OddDays = Interval - (Weeks * 5)
-
TheDate = TheDate - (Weeks * 7)
-
-
' Take OddDays weekend into account.
-
-
If (DatePart("w", TheDate) - OddDays) > 2 Then
-
TheDate = TheDate - OddDays - 2
-
Else
-
TheDate = TheDate - OddDays
-
End If
-
-
DateAddW = TheDate
-
End If
-
-
End Function
-
'************** End of Code **************
Save the module and name it AddWeekdaysOnly
Since your original code was - lastdate=dateadd("d",-1,[start date]+[number of days])
what you're actually doing is adding ([number of days] - 1) so we make that the Interval.
To invoke the function: - Interval = [number of days]-1
-
LastDate = DateAddW([Start Date], interval)
-
Welcome to TheScripts!
Linq ;0)> ADezii 8,834
Recognized Expert Expert
Hi
I been away for sometime. Pls help me with my new problem
i need to do a leave calculation using a text box.
I have a start date (date format) and number of days(number).
The calculation i can do is
lastdate=datead d("d",-1,[start date]+[number of days])
this gives the difference, but i need to minus the weekends from the total
I tried using "w" instead of "d" but no use
pls help me
Rj
This will point you in the right direction: Calculating Weekdays Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Tiernan |
last post by:
Hi all
I'm looking for a way to find the number of weekdays between 2 dates
In my form I have three fields for a begin date (dd)(mm)(yyyy) and
three for the end date (dd)(mm)(yyyy)
Now these values will be stored into a database and at the same time
there will be an e-mail generated and send to me that contains the
starting date en the end...
|
by: Raghu |
last post by:
Hello...
I am running into a problem while running a query..can some1 help..
this is the query :
**************
SELECT *
from Table S
where S.dtDate1 BETWEEN dateadd(year,1,dateadd(month,-1,getdate()))
AND dateadd(day,-1,(dateadd(month,1,dateadd(year,1,dateadd(month,-1,getdate())))))
***************
(first part of the date calculation...
|
by: Htk |
last post by:
I have two date fields:
-Inquiry Date
-Action Date
I'm trying to use a query expression on this.
Using the datediff expression, I can get the amount of days that seperate
the two dates. But I would like to know how I can get only a count of the
weekdays only.
I'm not sure if there is another expression I can use to get the result.
|
by: Annette Massie |
last post by:
I am trying to insert a record into a table via code and one of the
values to add I would like as a dateadd calculation on a value from a
query.
My code looks like this:
Set db = CurrentDb() ' if the table is in the same database
Set rsAdd = db.OpenRecordset("tblClientTreatment")
With rsAdd
.AddNew
!ClientID = Me.ClientID
|
by: rob |
last post by:
Hello all,
I have a report that is always due 14 weekdays (Monday thru Friday) from the
day it is suspensed.
I would like to use the DateAdd function using the weekday interval (
DateInterval.Weekday), but I've tried it and it returns the same value as
(DateInterval.Day).
Am I doing something wrong, or do I have the wrong expection for...
| |
by: atiq |
last post by:
I am trying to restrict the user to only enter date which is weekdays. so, it shouldn't allow a date that is weekend such as 08/04/07 (Sunday). Can someone help me with this issue. In short i want the user to enter a date which is Monday, Tuesday, Wednesday, thursday and Friday!
Additionally, i'm new to Databases so, could you tell me whether...
|
by: MLH |
last post by:
I'm thinking of an integer field in which I could write values up to
1+2+4+8+16+32+64 and to use these values later. Each of the
individual values would represent a weekday from Sunday to Saturday.
So if I were to look at a record for a newspaper publication and see
9 in the field, I could interpret that as meaning the publication was...
|
by: awojciehowski |
last post by:
Can any one point me in the right direction here...
I have a report that shows an entry and under that record there are several sub records...best way to explain it is imagine an order with several items in that order entry.
I have placed a DateAdd feature in a report that will show me 90 days after the date order was made.
My problem...
|
by: Mel |
last post by:
When I use the DateAdd function using "DateInterval.Weekday" it does
not return the correct date, well at least how I thought the weekday
option should work. It is counting weekends and I only want it to
count the weekdays (Mon-Fri). How can I get it to work? (using
Asp.net 2.0, vb.net)
Example:
dPlanFD = DateAdd(DateInterval.Weekday,...
|
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...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
| |
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |