I had read a previous article on calculating the number of years, months and days between 2 dates. They had used the DateDiff with a start date and an end date, similiar like below statement:
DateDiff("d",DateAdd("m",[Months],DateAdd("yyyy",[Years],[DateHired])),[DateTerminated]) AS Days
When I have dates like 2011-05-09 for the DateHired and 2011-09-08 for DateTerminated the days come out as a -1.
Here is another example: For the DateHired 2009-06-30 and the DateTerminated 2011-06-15 the days come out as -15.
One more example: DateHired 2008-09-29 and DateTerminated 2011-09-23 the days come out as -6.
I am able to get the years and months correctly but the some of the days end up being negative and incorrect.
2 3550
Am I correct in understand that you need each value calculated seperately? It is not enough for you to simply have the value in days? Is that the issue?
NeoPa 32,556
Expert Mod 16PB
Just as an introduction, this will probably work most reliably using the Year(), Month() & Day() function values for each date. It seems, from your question, that you are trying to work in SQL. A good idea to mention that generally, but I think we can assume from what you let slip.
The following should get you somewhere quite close : - SELECT Year([DateTerminated]) - Year([DateHired]) -
-
IIf(Month([DateTerminated]) = Month([DateHired]),
-
IIf(Day([DateTerminated]) < Day([DateHired]), 1,
-
IIf(Month([DateTerminated]) < Month([DateHired]), 1, 0))) AS [Years]
-
, (12 + Month([DateTerminated]) - Month([DateHired]) -
-
IIf(Day([DateTerminated]) < Day([DateHired]), 1, 0)) Mod 12 AS [Months]
-
, Day(DateAdd('d', -Day([DateHired]), DateAdd('m', 1, [DateHired]))) AS [DIM]
-
, ([DIM] + Day([DateTerminated]) - Day([DateHired])) Mod [DIM] AS [Days]
Let us know how well that works for you.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bambero |
last post by:
Hello all
Problem like in subject. There is no problem when I want to count days
between two dates. Problem is when I want to count years becouse of
leap years.
For ex.
between
2002-11-19...
|
by: MMFBprez |
last post by:
I am trying to compute storage charges by getting the number of months
between dates and multiplying it by a rate. I cannot get a correct
number of months if the date is greater than a year ago. ...
|
by: carl.barrett |
last post by:
Hi,
I have a continuous form based on a query ( I will also be creating a
report based on the same query).
There are 2 fields:
Date Obtained and Date Of Expiry
I want a further 3 columns...
|
by: Juan |
last post by:
Hi everyone,
is there a function that calculates the exact amount of Years, Months, and
Days between two days?
TimeDiff is not good enough, since it calculates, for example:
Date 1: Dec....
|
by: Jose |
last post by:
Exists a function that determined between two dates the years,months and
days?
Thanks a lot.
|
by: thebjorn |
last post by:
For the purpose of finding someone's age I was looking for a way to
find how the difference in years between two dates, so I could do
something like:
age = (date.today() - born).year
but that...
|
by: karthickkuchanur |
last post by:
Hai sir,
i assigned to calculate the age from current date ,i have the date of birth of employee from that i have to calculate the age dynamically,
i refer to google it was confusing...
|
by: johanneguaybenoit |
last post by:
Hi
I would like to know how to create a function or module to calculate
the age of a person in years months days.
and hours if feasable
But I really nead to know in years months days.
I...
|
by: shilpareddy2787 |
last post by:
Hello,
I have some total values, I want to calculate percenatge of these Total Values.
I want to divide the total with No. Of working Days Excluding Saturdays and Sundays in a given period.
...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |