Results 1 to 5 of 5

Thread: [RESOLVED] calculationg age from date to date (not today/now value)

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    8

    Resolved [RESOLVED] calculationg age from date to date (not today/now value)

    I'm trying to make a program for the school i work for, which calculate students age according to a certian date in years, months and days
    the program is for use at the school to calculate students ages in order to know they are applicable to which grade at the official date of the new academic year

    i.e. calculating if student's date birth was @ 1/1/2000 so i wanna know how many years, months, n days he is @ 1/10/2009

    im kinda new in the VB world n the programming world, but i searched the forum n found many results but it seemed they didnt worked correctly for my case

    i tried using dtpicker or entering the date manually in a textbox but i prefer using the dtpicker

    please give me an example how to make it, which function better to be used in such case

  2. #2
    Fanatic Member technorobbo's Avatar
    Join Date
    Dec 2008
    Location
    Chicago
    Posts
    864

    Re: calculationg age from date to date (not today/now value)

    perhaps something like this?
    Code:
    Dim bday As Date, target As Date
    Dim numMo As Integer, numYrs As Integer, numDays As Integer
    Dim tmpDate As Date
    
    bday = CDate("1/1/2000")
    target = CDate("1/10/2009")
    If target <= bday Then
        MsgBox "Dates aren't Valid"
        Exit Sub 'or function
    End If
    
    numYrs = DateDiff("yyyy", bday, target)
    tmpDate = DateAdd("yyyy", numYrs, bday)
    If tmpDate > target Then
        numYrs = numYrs - 1
        tmpDate = DateAdd("yyyy", -1, tmpDate)
    End If
    
    numMo = DateDiff("m", tmpDate, target)
    tmpDate = DateAdd("m", numMo, tmpDate)
    If tmpDate > target Then
        numMo = numMo - 1
        tmpDate = DateAdd("m", -1, tmpDate)
    End If
    
    numDays = DateDiff("d", tmpDate, target)
    
    MsgBox "Years=" & numYrs & " Months=" & numMo & " Days=" & numDays
    Last edited by technorobbo; Aug 26th, 2009 at 05:35 AM.
    Have Fun,

    TR
    _____________________________
    Check out my Alpha DogFighter2D Game Demo and Source code. Direct Download:http://home.comcast.net/~technorobbo/Alpha.zip or Read about it in the forum:http://www.vbforums.com/showthread.php?t=551700. Now in 3D!!! http://home.comcast.net/~technorobbo/AlPha3D.zip or read about it in the forum: http://www.vbforums.com/showthread.php?goto=newpost&t=552560 and IChessChat3D internet chess game

  3. #3
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: calculationg age from date to date (not today/now value)

    herewith i attached a project, which calculate year, month and days with datepicker
    hope this is what u need, if ur problm solved pls mark this thread as resolved
    thank u
    Attached Files Attached Files
    Last edited by seenu_1st; Aug 26th, 2009 at 05:31 AM.

  4. #4
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: calculationg age from date to date (not today/now value)

    hi techno
    thanks for ur code, it's nice

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2009
    Posts
    8

    Re: calculationg age from date to date (not today/now value)

    thank you all for your useful replies
    that code provided by techno was ideal to me
    i had just to change the date n put the dtpicker's value instead
    n puted it all under a command button and replacing the msgbox with 3 textboxes

    thanks sooo much for ur help

    Best Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width