473,769 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateDiff to calculate Weeks and Days function

2 New Member
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 5962
missinglinq
3,532 Recognized Expert Specialist
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.3333333333333 3
10\3 = 3

Hope this helps!

Welcome to TheScripts!

Linq ;0)>
Aug 26 '07 #2
Libber39
2 New Member
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 Recognized Expert Specialist
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
1845
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 following piece of asp to extract dates from an XML document and work with them to create the above mentioned result, however I can't get it to work Can someone please assist! Thank
1
8008
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 until completion: DateDiff("d",,) is TODAY the appropriate syntax for today's date? Could the function/expression even be set up that way, or do I need to do something else to get 'days until completion'? (My Access manuals do not mention a TODAY...
4
11917
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
4
5305
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 0day 9hrs.
5
6690
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
15505
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...
5
7240
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 of the DateDiff in the VB.NET runtime. private int DateDiff( string Interval, DateTime Date1, DateTime Date2 ) { int intDateDiff = 0; TimeSpan time = Date1 - Date2;
7
5955
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 returned. When I use "d" or "y" as the interval, the number of days is returned. What kind of calculation can I add to the statement to only count the number of week days? Is this possible? I was thinking I might have to run a query on a query...
12
1810
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
9589
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
9423
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
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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
5299
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...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3959
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
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.