473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

datediff less the weekends

ddtpmyra
333 100+
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 5108
youmike
69
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
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 100+
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,556 Expert Mod 16PB
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
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 ...
4
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...
4
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...
5
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...
7
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...
6
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
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...
1
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.