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

YEAR Function

I have a form with three fields:
STARTINGDATE
ENDINGDATE
YEARS

I would like the YEARS field to show the number of years which elaps from the
STARTINGDATE TO THE ENDINGDATE fields.

Please note that the first two fields have a mm/dd/yy format.

Any help with the Date Diff Function?

Thanks.
Nov 12 '05 #1
2 4025
Paolo wrote:
I have a form with three fields:
STARTINGDATE
ENDINGDATE
YEARS

I would like the YEARS field to show the number of years which elaps from the
STARTINGDATE TO THE ENDINGDATE fields.

Please note that the first two fields have a mm/dd/yy format.

Any help with the Date Diff Function?

Thanks.


Paolo,
Years = DateDiff("yyyy",[StartingDate],[EndingDate])

Note: the above will add 1 every time the year changes, whether or not a
full year has elapsed (i.e. 12/31/2002 to 1/1/2003 will = 1)

If you are looking for actual elapsed years, then use this:

In a query:
Years: DateDiff("yyyy", [StartingDate], [EndingDate]) -
IIF(Format([StartingDate], "mmdd") > Format([EndingDate], "mmdd"), 1, 0)

Directly as the control source of an unbound control:
Years=DateDiff("yyyy",[StartingDate],[EndingDate]) -
IIf(Format([StartingDate],"mmdd") > Format([EndingDate],
"mmdd"),1,0)

This Years calculation should NOT be saved to any table. Whenever you
need the result recalculate it.

--
Fred
Please reply only to this newsgroup.
I do not reply to personal email.
Nov 12 '05 #2
Thanks for your help. By the way I am still having some problem with
another Year Function.
In my form I also need to add additional FROM TO fields and wanted to
know if the Date Diff function has be used.

Basically my form has 5 fields:

YEARS
STARTINGDATE1
ENDINGDATE1
STARTINGDATE2
ENDINGDATE2

In each of the the 4 fields I wil be adding a date. The YEARS field
should sum the values I enter in the other 4 fields.

I have tried simply to add the two other fields to your code but it
does not work:

=DateDiff("yyyy",[STARTINGDATE1],[ENDINGDATE1],[STARTINGDATE2],[ENDINGDATE2])

I have also tried to use two other not visible fields, named A and, A1
and fill them with your origianal code and then add in the YEARS
field: =[A]+[A1].

This seems some solution, the only problem is that it may happen that
sometimes the STARTINGDATE2 and ENDINGDATE2 fields can be empty. When
this happens, it does not make to calculation. If these fields do show
dates, the calculations is processed.
Any further help?

Thanks.
Fredg <fg******@example.invalid> wrote in message news:<3y***********************@bgtnsc04-news.ops.worldnet.att.net>...
Paolo wrote:
I have a form with three fields:
STARTINGDATE
ENDINGDATE
YEARS

I would like the YEARS field to show the number of years which elaps from the
STARTINGDATE TO THE ENDINGDATE fields.

Please note that the first two fields have a mm/dd/yy format.

Any help with the Date Diff Function?

Thanks.


Paolo,
Years = DateDiff("yyyy",[StartingDate],[EndingDate])

Note: the above will add 1 every time the year changes, whether or not a
full year has elapsed (i.e. 12/31/2002 to 1/1/2003 will = 1)

If you are looking for actual elapsed years, then use this:

In a query:
Years: DateDiff("yyyy", [StartingDate], [EndingDate]) -
IIF(Format([StartingDate], "mmdd") > Format([EndingDate], "mmdd"), 1, 0)

Directly as the control source of an unbound control:
Years=DateDiff("yyyy",[StartingDate],[EndingDate]) -
IIf(Format([StartingDate],"mmdd") > Format([EndingDate],
"mmdd"),1,0)

This Years calculation should NOT be saved to any table. Whenever you
need the result recalculate it.

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ltamisin | last post by:
Hi Im working on a Year(Date) function right now, the output of that function is this "2005", my question is how can i change the format into this "05" Function: Year(Date) Output: 2005...
7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
14
by: Protoman | last post by:
Hi!!! I need some help on a project I'm that calculates leap years; I'm getting errors that I have no idea what they mean; here's the code: #include <iostream> #include <cstdlib> using...
2
by: Douglas | last post by:
I have a Vehicle MOT field in my table which i have as a Date field I dont really want to hold the year, just 'dd mmm' as MOTs are the same date every year. I have the field on my form as a...
14
by: Alan | last post by:
Hi everyone! I'm trying to produce a periodic financial report on projects from various departments. My database is set up with the tables tblDepartment, tblProjects, tblPeriods, and tblBudgets...
3
by: ethoemmes | last post by:
Hi Does anyone know of a function I can use to return the current tax year. Our tax year runs from 6 April. I need a function which will return the tax year for a given date. TIA
18
by: Bruno Baguette | last post by:
Hello, I have to design a table wich will store some action reports. Each report have an ID like this 1/2004, 2/2004, ... and each years, they restart to 1 (1/2004, 1/2005, 1/2006,...). So, I...
3
by: jannoergaard | last post by:
Hi I want to write a function that can return a sum for a given date range. The same function should be able to return the sum for the same period year before. Let me give an example: The...
4
by: ssylee | last post by:
I have set my year value in the register on my RTC (DS1302) to be 2008 using this code: // This function sets the year on the RTC // Note: The year takes in only the last two digits of the year...
4
by: hallsers | last post by:
Here is the problem i am having: - When a user logs in, on page load it will take the dob of all users in a stored friends list and compare them against the following conditions - To display any...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
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
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...

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.