473,499 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating years between dates

1 New Member
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 1437
gnawoncents
214 New Member
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 New Member
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 New Member
@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,557 Recognized Expert Moderator MVP
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
4370
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
9974
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
15656
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
2080
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
3728
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
1864
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
2133
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
2494
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
2386
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
1850
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
7131
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
7174
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,...
1
6894
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
5470
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,...
0
4600
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...
0
3099
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...
0
1427
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 ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
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...

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.