473,421 Members | 1,625 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,421 software developers and data experts.

DateDiff to calculate Weeks and Days function

Hi everyone,

Have a query on how to calculate the amount of weeks and days contained in a number in an access query. ie: the difference in days between 2 dates amounts to 17 days. I want to now calculate in the query the amount of weeks and days within the 17 days to show 2 weeks 3 days.

I can create the function within excel, (A1 as cell with the days within it) as:

=INT(A1/7) & " Weeks, " & MOD(A1,7) & " days"

but cant seem to get the expression right in my Access query when I use INT and MOD.

I have found a very similar post from only a couple of weeks ago which is very close and helpful, but unfortunately my coding skills are not so good and so am having trouble dealing with the vb in the modules to create my own function.

http://www.thescripts.com/forum/thre...eeks+days.html

I seem to be so close, but a) am unsure of how I write this in VB and then b) what I then need to write within my Access Query to bring back the weeks and days.

Any help is very much appreciated.

many thanks,
Gerry
Aug 26 '07 #1
3 5935
missinglinq
3,532 Expert 2GB
For a calculated field in your query called WeeksDays this should do:

Expand|Select|Wrap|Line Numbers
  1. WeeksDays: (datediff("d",StartDate,EndDate)\7) & " Week(s) " & datediff("d",StartDate,EndDate) mod 7 & " Day(s)" 
You'll note the use of the \ instead of the / when dividing by 7. This returns only the integer part of the division.

10/3 = 3.33333333333333
10\3 = 3

Hope this helps!

Welcome to TheScripts!

Linq ;0)>
Aug 26 '07 #2
The scripts is a modern marvel. Your answer has worked like a charm and my query now looks a work of art. Cant thank you enough for your time and help, it is really appreciated.

Cheers
Gerry
Aug 27 '07 #3
missinglinq
3,532 Expert 2GB
Glad we could help!

Linq ;0)>
Aug 27 '07 #4

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

Similar topics

1
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...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
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...
4
by: perryche | last post by:
4 Fields: Date1 Time1 Date2 Time2 How do I calculate days/hours diff between Date1Time1 & Date2Time2? e.g. 3days 12hours If it were 05/02/05 11pm and 05/03/05 8am? It should say...
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...
5
by: sr | last post by:
Anyone know of a better way to simulate a datediff for C#, i.e., without referencing the VB.NET runtime? Only added the functionality that was needed for me so it is not the full implementation...
7
by: JenM | last post by:
Hi. I am a novice user. I am using the datediff function in a query. I am trying to calculate the number of week days between two dates. When I use "m" as the interval, the number of weeks is...
12
by: andyoye | last post by:
I have two date fields(startDate, endDate) in a form and I want to calculate number of days between startDate & endDate. Thanks
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
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...
1
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...
0
agi2029
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,...

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.