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 12171
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 date . But now I want an extra line in this
e-mail that tells me howmany days there are between the...
|
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 comes out to be '2005-05-01' and
|
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 this
| |
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 the validation rule given should be used during table design or on the form date field. Any help...
|
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
released on Sundays (1) and Wednesdays (8). A value of 127 would
indicate a daily paper publishing...
|
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 lies in that the DateAdd feature is now showing multiple times under each order...it lists the same...
|
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, 10, "11/04/2008")
'dPlanFD = #11/14/2008# 'I want it to return #11/18/2008#
|
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,...
|
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...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |