Solved

Age Calculation including Leap Year

Posted on 2008-10-08
13
897 Views
Last Modified: 2012-05-05
Hi Experts

I need to calculate the difference in days between the fields below. This needs to include a extra day if there is Leap Year.

Start Date       End Date
12/01/2007     10/31/2008 = 0.9171 (No leap year considered)

Thanks.
0
Comment
Question by:Sariff
  • 6
  • 4
  • 3
13 Comments
 

Author Comment

by:Sariff
ID: 22671548
Start Date       End Date
12/01/2007     10/31/2008 /365.25 = 0.9171 (No leap year considered)

0
 
LVL 75
ID: 22671558
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 22672232
> .. the difference in days between the fields ..

intDiffDays = DateDiff("d", [Start Date], [End Date])

leap year or not.

> 0.9171

That looks more like a partial year.
So what are you looking for?

/gustav


0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 75
ID: 22672303
I forgot to mention to look for Gustav's solutions in the links I posted :-)

mx
0
 

Author Comment

by:Sariff
ID: 22672827
Im checking into them...I will post back soon. Thanks
0
 

Author Comment

by:Sariff
ID: 22675669
The "days" difference for the example above is 335 (non leap year), 336 I need the formula to calc correctly for a Leap Year as well as non leap year.
Below is the calc I am using:
 DateDiff("d",[LastBirthday],[LASTDAY_OF_MONTH]+1)/365

How can this be setup to know when it is a leap year and when not?
0
 
LVL 75
ID: 22675727
gustav is your guy for any date / time type calculation.  In the one link, is Function covers every case known to Man.

mx
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 22676156
Thanks Joe. Haven't thought about this way but it may be true.

But there is more. How about this, the 3-3-System (r), which may be new to you, invented by a Swede, Sune Nygren:

  http://www.tretre.se/korteng.shtml

Notice the calendars which are "imune" to leap years:

  http://www.tretre.se/standard.shtml

By the way, it was me who persuaded him to define a start date which he set to 1998-04-06.

/gustav
0
 

Author Comment

by:Sariff
ID: 22677359
Thanks for the information. I am hoping for something I can run in SQL as the result will dump to an Excel doc...
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 22678224
If it is in Access, it can be "dumped" to Excel, SQL or not.

Isn't it about time you try to tell us what you are trying to achieve?

/gustav
0
 

Author Comment

by:Sariff
ID: 22678395
gustav

I am trying to calculate the Age of an employee to the exact day in years and the lapsed days since his/her last birthday.

0
 

Author Comment

by:Sariff
ID: 22678448
I have the Age in years done, but the Leap year causes a problem with calculating the lapsed days
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 22679303
That could be counting the days from the last birthday. Leap years will have no impact as a day is a day. Thus, for some years you may get x years and 365 days just before the birthday:

datDob = <some birthday>
intAgeYears = Age(datDob)
intAgeDays = DateDiff("d", DateAdd("yyyy", intAgeYears, datDob), Date)

strAgeYearsDays = CStr(intAgeYears) & " years, " & CStr(intAgeDays) & " days"

/gustav
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can i Import Access Table Into Oracle Using Toad 36 166
Any Way to Print an Import Spec? 3 29
backup programme - VBA 3 22
Criteria for Date for DCount 4 17
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now