I am trying to get the date difference between two dates but I don't
want the function to include weekends in the calculation. Does anyone
have an idea on how to make this work? 6 7627 ke**********@gmail.com wrote: I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
Here is what I use to count weekend days:
'---Begin Code
Public Function CountWeekendDays(dtStart As Date, dtEnd As Date) As
Integer
Dim intSat As Integer
Dim intSun As Integer
'This function assumes dtStart <= dtEnd
CountWeekendDays = 0
intSat = DateDiff("d", GEDay(dtStart, 7), LEDay(dtEnd, 7)) / 7 + 1
intSun = DateDiff("d", GEDay(dtStart, 1), LEDay(dtEnd, 1)) / 7 + 1
CountWeekendDays = Ramp(intSat) + Ramp(intSun)
End Function
Public Function LEDay(dtX As Date, vbDay As Integer) As Date
LEDay = DateAdd("d", -(7 + WeekDay(dtX) - vbDay) Mod 7, dtX)
End Function
Public Function GEDay(dtX As Date, vbDay As Integer) As Date
GEDay = DateAdd("d", (7 + vbDay - WeekDay(dtX)) Mod 7, dtX)
End Function
Public Function Ramp(varX As Variant) As Variant
Ramp = IIf(Nz(varX, 0) >= 0, Nz(varX, 0), 0)
End Function
'---End Code
Sample Call:
MsgBox (CountWeekendDays(#3/1/06#, #5/1/06#))
18
Use the same dates you are using for your DateDiff in this function and
subtract the result from your DateDiff result.
James A. Fortune CD********@FortuneJames.com
I am sure that works well in forms or macros, but will it work as an
expression in a query?
I should have noted, I am trying to do this through a query.
Sorry CD********@FortuneJames.com wrote: ke**********@gmail.com wrote: I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
Here is what I use to count weekend days:
'---Begin Code Public Function CountWeekendDays(dtStart As Date, dtEnd As Date) As Integer Dim intSat As Integer Dim intSun As Integer
'This function assumes dtStart <= dtEnd CountWeekendDays = 0 intSat = DateDiff("d", GEDay(dtStart, 7), LEDay(dtEnd, 7)) / 7 + 1 intSun = DateDiff("d", GEDay(dtStart, 1), LEDay(dtEnd, 1)) / 7 + 1 CountWeekendDays = Ramp(intSat) + Ramp(intSun) End Function
Public Function LEDay(dtX As Date, vbDay As Integer) As Date LEDay = DateAdd("d", -(7 + WeekDay(dtX) - vbDay) Mod 7, dtX) End Function
Public Function GEDay(dtX As Date, vbDay As Integer) As Date GEDay = DateAdd("d", (7 + vbDay - WeekDay(dtX)) Mod 7, dtX) End Function
Public Function Ramp(varX As Variant) As Variant Ramp = IIf(Nz(varX, 0) >= 0, Nz(varX, 0), 0) End Function '---End Code
Sample Call: MsgBox (CountWeekendDays(#3/1/06#, #5/1/06#))
18
Use the same dates you are using for your DateDiff in this function and subtract the result from your DateDiff result.
James A. Fortune CD********@FortuneJames.com
I found a solution that looks like it works in query functions
DateDiff('d',[test]![date1],[test]![date2],2)-(IIf(DateDiff('ww',[test]![date1],[test]![date2],2)=0,DateDiff('ww',[test]![date1],[test]![date2],2),(DateDiff('ww',[test]![date1],[test]![date2],2))*2)) ke**********@gmail.com wrote: I am sure that works well in forms or macros, but will it work as an expression in a query?
I should have noted, I am trying to do this through a query.
Sorry
CD********@FortuneJames.com wrote: ke**********@gmail.com wrote: I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
Here is what I use to count weekend days:
'---Begin Code Public Function CountWeekendDays(dtStart As Date, dtEnd As Date) As Integer Dim intSat As Integer Dim intSun As Integer
'This function assumes dtStart <= dtEnd CountWeekendDays = 0 intSat = DateDiff("d", GEDay(dtStart, 7), LEDay(dtEnd, 7)) / 7 + 1 intSun = DateDiff("d", GEDay(dtStart, 1), LEDay(dtEnd, 1)) / 7 + 1 CountWeekendDays = Ramp(intSat) + Ramp(intSun) End Function
Public Function LEDay(dtX As Date, vbDay As Integer) As Date LEDay = DateAdd("d", -(7 + WeekDay(dtX) - vbDay) Mod 7, dtX) End Function
Public Function GEDay(dtX As Date, vbDay As Integer) As Date GEDay = DateAdd("d", (7 + vbDay - WeekDay(dtX)) Mod 7, dtX) End Function
Public Function Ramp(varX As Variant) As Variant Ramp = IIf(Nz(varX, 0) >= 0, Nz(varX, 0), 0) End Function '---End Code
Sample Call: MsgBox (CountWeekendDays(#3/1/06#, #5/1/06#))
18
Use the same dates you are using for your DateDiff in this function and subtract the result from your DateDiff result.
James A. Fortune CD********@FortuneJames.com
Similar to others, and does work in query
workdays
=DateDiff("d",[StartDate],[EndDate])-(DateDiff("ww",[StartDate],[EndDate],7)+DateDiff("ww",[StartDate],[EndDate],1))
+ 1
Ron2006 wrote: Similar to others, and does work in query
workdays =DateDiff("d",[StartDate],[EndDate])-(DateDiff("ww",[StartDate],[EndDate],7)+DateDiff("ww",[StartDate],[EndDate],1)) + 1
I have read here that using ww for some versions of Access doesn't
return the correct value for some dates. That's why I didn't use it.
Maybe someone can clarify which situations may be dangerous..
James A. Fortune CD********@FortuneJames.com ke**********@gmail.com wrote: I am sure that works well in forms or macros, but will it work as an expression in a query?
I should have noted, I am trying to do this through a query.
Sorry
If the code is placed in a module rather than behind a form then you
can call it from a query.
James A. Fortune CD********@FortuneJames.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tim::. |
last post by:
I am having some difficulties with the function Datediff! I am trying to calculate the number of days between two given date
E.G: Number days between 03-05-2004 and 05-05-2004 =
I am using the...
|
by: Paolo |
last post by:
I am having some problem with a Year Function.
I have form on which I have 4 field which indicate dates and an
additional form which sums those dates:
These are the fields:
YEARS...
|
by: mcbill20 |
last post by:
Hello all. I have a really basic question that I hope someone has a
better answer for. I apologize in advance-- I know this is probably a
really basic question but I am used to Oracle rathern than...
|
by: haydn_llewellyn |
last post by:
Hi,
My company runs on a fiscal calendar that starts on the first monday in
July, and is based on a 13 week quarter (4 weeks, 4 weeks, 5 weeks).
What I need, is a way of relating Date() to the...
|
by: Kd |
last post by:
I am currently using a form with Weekdays
Mon
Tues
Wed
Thur
Fri
This is generated by a table that the days are being entered manually
I would like to create a form that the days updated...
|
by: Price Brattin |
last post by:
Why is the DateDiff function in the following code returning zero?
Dim FileDate, TransmissionDate as Date
Dim TranDay, FileDay, DayDiff as Inteter
TransmissionDate = #2/5/2006 1:57:56 PM#...
|
by: dgmoore |
last post by:
I've hit a snag - I know this is easy, but the logic is escaping me. I
need to set criteria in a query to find dates in a date field that lie
between Tuesday of the current week and Tuesday of the...
|
by: Rudi Hausmann |
last post by:
Hi!
I have a column with a date.
In another column I want to show the weekday of this date.
I have following code:
<asp:BoundField DataField="myDate" HeaderText="WeekDay"...
|
by: ddtpmyra |
last post by:
I have below query inside the ms access, but this query counts all the days including the weekend but I only wanted to count the NUMBER of weekday (Monday to Friday). Please help
Number of Days...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |