Solved

Date Diff in Expression builder Access

Posted on 2009-04-15
7
501 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Search for text in a .txt file 14 47
Calculation in Access 5 29
Access check if a table is open 4 44
Rounding precision in MS Access 9 31
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

825 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