p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Visual Basic 2005 Basics (http://p2p.wrox.com/forumdisplay.php?f=137)
-   -   Using Date in Visual Basic 2005. (http://p2p.wrox.com/showthread.php?t=70079)

sheelnathkekre August 15th, 2008 08:15 AM

Using Date in Visual Basic 2005.
 
How to get age in years(rounded off to nearest number) in a textbox3,suppose we are having Date of birth of a person in textbox2 and today's date in textbox1?


BrianWren August 15th, 2008 09:42 AM

Something like this:
Code:

  Year(CDate("January 15, 2008")) - Year(CDate("September 9, 1985"))
almost gives you the answer. But it is only accurate after 9/9 any year. So if the date is after December 31, midnight (after New Year's), but before the birthday, you need to subtract 1.

Statements that are True or False = -1 if True, and 0 if False.

Adding a minus value subtracts the absolute value of it.

So if you [u]add</u> to the statement’s value (the purple part is pseudocode)
Code:

  + (TheDayOfTheYearOf(CDate(textbox1.Text)) < _
     TheDayOfTheYearOf(CDate(textbox2.Text)) _
    )



All times are GMT -4. The time now is 07:29 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.