Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calculate A Persons Age

Posted on 2003-11-20
4
Medium Priority
?
404 Views
Last Modified: 2010-05-01
How do i compute a persons age? if there's a leap year?
0
Comment
Question by:karmicrepublic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 13

Expert Comment

by:AlbertaBeef
ID: 9795009
0
 
LVL 13

Accepted Solution

by:
AlbertaBeef earned 750 total points
ID: 9795022
This is from a PAQ:  http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20626567.html

Private Sub Command1_Click()
'2003 05 26_
'1976 10 31
'--------------
'     26 06 25

Dim dtm1 As Date
Dim dtm2 As Date
Dim intYear As Integer
Dim intMonth As Integer
Dim intDay As Integer

    dtm1 = #5/26/2003#
    dtm2 = #10/31/1976#
   
    intYear = Abs(Year(dtm2) - Year(dtm1))
    If (Month(dtm1) < Month(dtm2)) Or ((Month(dtm1) = Month(dtm2)) And (Day(dtm1) < Day(dtm2))) Then
        intYear = intYear - 1
    End If
   
    If Month(dtm1) > Month(dtm2) Then
        intMonth = Month(dtm1) - Month(dtm2)
    Else
        intMonth = (12 - Month(dtm2)) + Month(dtm1)
        If Day(dtm1) < Day(dtm2) Then
            intMonth = intMonth - 1
        End If
    End If
   
    If Day(dtm1) > Day(dtm2) Then
        intDay = Day(dtm1) - Day(dtm2)
    Else
        intDay = (30 - Day(dtm2)) + Day(dtm1)
    End If

    MsgBox intYear & "-" & intMonth & "-" & intDay
End Sub
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 9795027
test for leap year

Public Function IsLeapYear(Yr As Integer) As Boolean

'Set default return value
IsLeapYear = False
      
'If year is divisible with four then it's a leap year, unless
'is divisible by 100 but not by 400...
If Yr Mod 4 = 0 Then

      IsLeapYear = True

      If Yr Mod 100 = 0 Then

            If (Yr Mod 400) Then IsLeapYear = False

      End If

End If

End Function
0
 
LVL 13

Expert Comment

by:AlbertaBeef
ID: 9795095
Why the 'B' grade?  I supplied two working links and one with source code.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

730 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