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

Calculating years between dates

In an update query I need to calculate the number of years between 12/31/2012 and various years. The integer function is to be used with the calculation. I get ridiculous negative answers.
Example. 12/31/2012- 1/5/2008
I am using (12/31/2012-[date])/365.25
Any help would be appreciated
Feb 21 '18 #1
4 1435
gnawoncents
214 100+
Welcome to Bytes, Stephcar!
Writing your code that way is actually giving you 12 divided by 31 divided by 2012 minus CurrentDate divided by 365.25. That is why it's returning a negative value. if 12/31/2012 is a fixed date, you're probably looking for something like the code below.
Expand|Select|Wrap|Line Numbers
  1. (Date - DateValue("12-31-2012")) / 365.25
  2.  
If it is not a set date and can change, check out NeoPa's caution on setting up dates correctly at the thread link below.
https://bytes.com/topic/access/answe...listbox-report
Feb 22 '18 #2
Narender Sagar
189 100+
I think, your question is not properly explained. Why are you dividing [date] with 365.25? Can you please explain your objective of dividing this?
Feb 22 '18 #3
gnawoncents
214 100+
@Narender, as I read it, Stephcar wants the number of years between the current date and some past date. Dividing by 365.25 is one way of getting the difference converted into years.
Feb 22 '18 #4
NeoPa
32,556 Expert Mod 16PB
I suspect you're wanting :
Expand|Select|Wrap|Line Numbers
  1. (Date - DateValue("2012-12-31")) / 365.25
yyyy-m-d is a standard, and non country specific, version of a date string recognised by SQL as well as VBA. The linked question is all about SQL. This one is also about SQL as the question's about an UPDATE query, but it works for VBA too.

NB. Using an UPDATE query is generally not recommended. Such a result would be better as a calculated value in most circumstances.
Feb 22 '18 #5

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

Similar topics

26
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
8
by: Mojca | last post by:
What is formula that get days between two dates? Npr: 11.03.1998 – 1.7.2005 Thank you, Mojca
4
by: jamesyreid | last post by:
Hi, I'm really sorry to post this as I know it must have been asked countless times before, but I can't find an answer anywhere. Does anyone have a snippet of JavaScript code I could borrow...
2
by: Carl | last post by:
Hi, I have a query that produces an output similar to the sample shown below. These records are based on certain criteria and a date range selected from a form. I need to create some kind of...
4
by: Toine | last post by:
Hello, I'm new to Python so please bare with me... I need to calculate a date that is exactly 31 days from the current date in YYYY-MM-DD format. I know that date.today() returns the current...
2
by: mtchampi | last post by:
Hello all, I have a limited SQL background, and I am responsible for creating a monthly report that displays separate tables for the following: 1. Calculate individual monthly totals of files...
3
by: mlcampeau | last post by:
Hi guys, I am trying to run a query that calculates when employees become eligible for supplemental vacation. This occcurs once the employee has reached 5, 10, 15, etc years of service. I got the...
18
by: mlcampeau | last post by:
I have a lengthy query that I am now trying to filter. The query calculates an employee's Anniversary Date in which they are eligible for the next level of Annual Vacation. (i.e. For 1-6 years of...
1
by: trixxnixon | last post by:
Hi all, I have been handed a new project that required me to update a database... a rather complicated database. I take that back, its not that it is super complicated, I am just a novice user...
1
by: Nosobright | last post by:
I am a beginer. I have been tasked at projecting failure dates of Batteries. Batteries have different failure rates. So when we install a battery "Change Date" and the known life is 3 yrs "Failure...
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.