Solved

Date Diff in Expression builder Access

Posted on 2009-04-15
7
499 Views
Last Modified: 2013-11-29
In my expression builder i am creating a Field called ageing as

Ageing:  [TblAfterCompare]![BIRTHDATEAS] - [TblAfterCompare]![AmendDate]

Birthdate is always earlier or = to Amend Date
But i want the result to give only the count of Business Days (excluding saturdays and sundays), how do i modify it ?
Regards
0
Comment
Question by:siva_iaf
  • 4
  • 3
7 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24146976
There is this
http://www.mvps.org/access/datetime/date0006.htm
but do you also want to consider public holidays?
0
 

Author Comment

by:siva_iaf
ID: 24146996
I need to exclude only the Saturday and Sundays..
Moreover this is giving a Code which i dont wish as I want to have it in a Expression builder in a Query Design Grid.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24147049
Problem with msaccess sql, unlike other sql like t-sql (sql server), you cant do more programmatic stuff. Using the first function in that link, you save it to a module (ensure module name not the same as function name) then can use it in a query

select WorkingDays(BirthdateAs, AmendDate) AS MyDiffDate



0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 65

Expert Comment

by:rockiroads
ID: 24147055
Ageing: WorkingDays(BirthdateAs, AmendDate)
0
 

Author Comment

by:siva_iaf
ID: 24147130
In the code below..I want it to update in TableA Field Name Ageing...on running this query..

I have saved the below mentioend query as Module1.
On Error GoTo Err_WorkingDays
 

Dim intCount As Integer
 

'StartDate = StartDate + 1

'If you want to count the day of StartDate as the 1st day

'Comment out the line above
 

intCount = 0

Do While BirthDate <= AmendDate

'Make the above < and not <= to not count the EndDate
 

Select Case Weekday(BirthDate)

Case Is = 1, 7

intCount = intCount

Case Is = 2, 3, 4, 5, 6

intCount = intCount + 1

End Select

BirthDate = BirthDate + 1

Loop

Ageing = intCount
 

Exit_WorkingDays:

Exit Function
 

Err_WorkingDays:

Select Case Err
 

Case Else

MsgBox Err.Description

Resume Exit_WorkingDays

End Select
 

End Function

Open in new window

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24147255
u can use it in a update statement like thos

update mytable
set myfield = workingdays(somedate, someotherdate)
0
 

Author Closing Comment

by:siva_iaf
ID: 31570369
Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now