473,804 Members | 3,790 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datediff less the weekends

ddtpmyra
333 Contributor
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 Open: DateDiff('d',[dbo_Ticket]![date_opened],Date())

I tried to us the 'w' and 'ww' but it counts the number week not the number of days in a week.

Number of Days Open: DateDiff('w',[dbo_Ticket]![date_opened],Date())

Thanks!
Jul 28 '08 #1
4 5144
youmike
69 New Member
You will probably best meet this need by writing VBA code to test the day of the week for each date between the startdate andthe enddate and incrementing a counter if the day of the week is between Monday and Friday.

You also could do this in SQL using a "WHERE" clause and the COUNT option:

Expand|Select|Wrap|Line Numbers
  1. SELECT Count(tblDiary.DiaryDate) AS CountOfDiaryDate
  2. FROM tblDiary
  3. WHERE (((DatePart("w",[DiaryDate])) Between 1 And 5));
The benefit of the VBA alternative is that you could adjust it to exclude holidays
Jul 29 '08 #2
Panado
1 New Member
Here is a function that sould do the job.
Expand|Select|Wrap|Line Numbers
  1. Private Function DiffJour(ByVal DateDeb As Date, ByVal DateFin As Date) As Integer
  2.  
  3. ' Calculates number of days betwwen two dates excluding saturdays and sundays
  4.  
  5. ' DiffJour = (DateFin - DateDeb) - (saturdays + sundays).
  6.  
  7.     On Error GoTo Err_DiffJour
  8.  
  9.     Dim DiffJr As Integer
  10.  
  11. ' Base difference
  12.     DiffJr = DateDiff("d", DateDeb, DateFin)
  13.  
  14. ' Eliminate saturdays and sundays
  15.     Do While DateDeb <= DateFin
  16.         If Weekday(DateDeb, 7) <= 2 Then
  17.             DiffJr = DiffJr - 1
  18.         End If
  19.         DateDeb = DateDeb + 1
  20.     Loop
  21.  
  22. ' In case there is no working day between the two dates.
  23.     If DiffJr < 0 Then
  24.         DiffJr = 0
  25.     End If
  26.  
  27.     DiffJour = DiffJr
  28.  
  29.     Exit Function
  30.  
  31. Err_DiffJour:
  32.     MsgBox Err.Description
  33. End Function
Jul 29 '08 #3
ddtpmyra
333 Contributor
To Panado:

Need more help Im a newbie using the access. My question is... If i'll do this function inside access how can I apply or call this function is it on load of a report?

thanks,
Myra
Jul 29 '08 #4
NeoPa
32,579 Recognized Expert Moderator MVP
I would suggest using modular arithmetic for the number of whole weeks, then using Weekday() determine which working days are between the two weekdays.
Aug 5 '08 #5

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

Similar topics

8
5931
by: inamori | last post by:
I face that problems 07/01/2003 06/30/2006 ---------> it should be 3 01/01/2003 02/28/2005 --------->could i get 2 years and 2 months 01/01/2003 03/01/2005 --------->could i get 2 years and 2 months and 1
4
12223
by: John Smith | last post by:
Hi, I'm having trouble working out the best way of calculating the time difference between two times on the same day. The example I have found does return the hours (in this case 8) but forgets the minutes. I am looking to return the hour & the minute but i've had a look at the dateDiff format and this doesn't seem possible ?
4
11920
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 STARTINGDATE1 ENDINGDATE1 STARTINGDATE2
5
6693
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 Access. I have a database where they customer wants to purge records from certain tables after three years. When I was asked to make the changes I originally thought this was an incredibly simple thing to do. I looked at the function list and...
7
15509
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using DateDiff in VB.NET which is only available in C# if you don't mind linking in Microsoft.VisualBasic.dll to your C# application. I wanted to avoid this so set about a pure C# solution which uses a combination of TimeSpan in whole days and the...
6
7651
by: kevinjwilson | last post by:
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?
4
4448
by: J-P-W | last post by:
Hi, I have a system that records insurance policies. If the policy is cancelled then any part of a month insured is deducted from the premium, so a policy that ran for 32 days would get a 10 month rebate so would 58 days etc. I've used:
1
1722
by: rn5a | last post by:
I have 2 variables - 'dt1' & 'dt2' - of type DateTime. Assume that one of the values of 'dt1' (which is being retrieved from a DB table) is 27/12/2006 6:54:27 AM & the value of 'dt2' is the current date & time, say, 30/12/2006 3:09:22 PM. I have the following code which uses the built-in DateDiff function: Dim dt1 As DateTime Dim dt2 As DateTime
2
2632
by: lbseong | last post by:
Hi, I am new to this forum please help. I need to schedule a job to send out an email if found there is a records older than 1 minute (compare to current date time against createddate) and the email will contain the itemid. mytable design 1.) itemid int createddate getdatetime() summaryid varchar startdate datetime enddate datetime
0
9705
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
9576
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
10568
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...
1
10311
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,...
0
10074
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
6847
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
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.