Donate SIGN UP

Dates and times

Avatar Image
Potatoman | 23:41 Tue 09th Nov 2004 | Technology
8 Answers

How do i work out a persons age given their DOB? I have to write a VB.net computer program that does this, so i cant cheat with excel!

Gravatar

Answers

1 to 8 of 8rss feed

Best Answer

No best answer has yet been selected by Potatoman. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.

Try this http://www.daniweb.com/techtalkforums/thread13318.html

but I have to ask: difference between cheating with Excel and posting for the answer? :-)

Lookup the TimeSpan class.  Using DateTime.Now and the person's DoB  (DateTime.Parse(thePersonsDateOfBirth), you should be able to figure out their age down to the millisecond.  Hope this helps. 
How easy do you want this to be?  I can give you the code in 2 lines if you want it.
Question Author
obonio - yes please!

        Dim ageTimeSpan As New TimeSpan(DateTime.Now.Ticks - DateTime.Parse("25-Nov-1975").Ticks)
        MessageBox.Show(Math.Floor(ageTimeSpan.Days / 365.25) & " years old")

Hmm, this blinking thing has screwed the code up.  Remeber it's on 2 lines only and there's no   in it either.  First line is from Dim to the end of .Ticks).  2nd line if from the start of MessageBox to the end.

If you need any explanation, let me know.

Question Author
obonio, thanks for your help! BTW, i passed the assignment!
Congrats.  Great stuff.  Make sure you understand what's going on though!  Nothing learnt is nothing gained!

1 to 8 of 8rss feed

Do you know the answer?

Dates and times

Answer Question >>