473,387 Members | 1,573 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 interval use both month & week

26
I want to set up a Query to show the diffence between 2 dates and the output to be in months and weeks. So the child is 15months and 2weeks (15/2). I have been try to modify DateDiff Age: DateDiff("m/ww",[ifdob],[DateEntered]) but cant get it to work. Any suggestions.
thanx
Steve
Aug 10 '07 #1
5 3782
missinglinq
3,532 Expert 2GB
Obviously, when you do these kinds of calculations, you have to make some compromises, i.e what are you going to consider to be a month, 30 days or 30.41666 days and so on. Then you have to decide what you want to do with the leftover days. The difference between two dates is seldom going to be exactly X Months and Y Weeks.

Using 30 days to a month and being satisfied with the whole months and weeks (discarding the part of a week) is fairly simple. So would getting Months/Weeks/Days. And this doesn't have to be done with a query; you can simply do a calculation in your form.

Think about this and post back.

Welcome to TheScripts!

Linq ;0)>
Aug 10 '07 #2
BUmed
26
I was just wondering if datediff could be used to output a combination of intervals. But you are saying that I would have to calculate it using another method if it is to be month and weeks. For example if a child is 13m, 2week and 3days it would be ok to round off the days to simple display 13m and 2weeks. Can you suggest the best way of doing this.
thanx
Aug 13 '07 #3
missinglinq
3,532 Expert 2GB
There is no native Access function that will return the difference in months and weeks, so you have to build your own.

Expand|Select|Wrap|Line Numbers
  1. DaysDiff = DateDiff("d", [ifdob], [DateEntered])
  2. Months = Int(DaysDiff / 30)
  3. Days = DaysDiff Mod 30
  4. Weeks = Int(Days / 7)
  5. Days = Days Mod 7
  6. AdjustedWeeks = Weeks + (Round(Days / 7))
  7.  
  8. DateDiff Age = Months & " Month(s) and " & AdjustedWeeks & " Week(s)"
  9.  
Line # 1 uses DateDiff to determine the difference between the two dates in days.

You'll remember from grade school that when you divide a number you get a whole number and a remainder. In Access, to get only the whole number, you format your answer by using the Int (stands for Integer) function, so Line # 2 gets the number of whole months by using Int(Days/30)

In Access, to get just the remainder from a division operation, you use a function called MOD. 10 / 3 = 3 with 1 remaining, so 10 MOD 3 = 1. Line # 3 uses this to find the days remaining after the months have been calculated.

Lines # 4 and 5 repeats this same operation, using 7 this time to calculate the number of weeks and days left in the remaining number of days.

The final line puts these concatenates these segments to give you your final answer.

Linq ;0)>
Aug 13 '07 #4
BUmed
26
Thanx so much. Im just starting to learn vb and this is a big help
Aug 13 '07 #5
missinglinq
3,532 Expert 2GB
Glad we could help.

Linq ;0)>
Aug 13 '07 #6

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

Similar topics

3
by: johkar | last post by:
I need to document.write out a select list populated with the dates for the first and third Wednesday of each month. How do I get to the actual days? <select name="mySelect"> <option value="Oct...
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...
10
by: Karsten Hilbert | last post by:
I have the need to output intervals (ages in this case). PostgreSQL takes great care to handle months correctly (eg take into account varying months lengths). This is only possible if either end...
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...
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...
5
by: Danyork | last post by:
Hello, I have a query with a DateDiff function in it. I was wondering if it is possible to make the "interval" a user defined field. I have already created a form with an unbound value box with...
2
by: muddasirmunir | last post by:
i am using vb 6 , i had place two datepicker in form now i want to calcuate differcen of month in two date for this i used the function datediff i had try it withh many syntax but getting error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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?
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
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
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
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,...

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.