using datetimepicker

choknut

Newcomer
Joined
May 18, 2006
Messages
4
i had a datetimepicker named dtpBirthDate, and want to use this as a meduim for obtaining birthdate of a user, what i want to happen exactly is upon choosing the date, three(3) textboxes namely, tboxYears, tboxMonths,tboxDays would be fill up by the number of years,months,and days the user was.

here's the code:
Visual Basic:
Dim tStart As DateTime = Me.dtpBirthDate.Value
Dim tFinish As DateTime = Now()

Dim TotalTime As TimeSpan = tFinish.Subtract(tStart)
Dim dd As Double = TotalTime.TotalDays

Me.tboxYears.Text = ((TotalTime.TotalDays) / 365.25).ToString
Me.tboxMonths.Text = (((TotalTime.TotalDays) / 365.25) * 12).ToString
Me.tboxDays.Text = TotalTime.TotalDays.ToString

problem is it shows how many years,months and days it takes from the selected day to now, which is not the way i really wanted to show...and also it shows in decimal numbers not whole number.thanks again...
 
Last edited by a moderator:
Not quite sure exactly what you are trying to display - if you mean to show something like 16 years, 4 months and 17 days then the timespan object has the properties .Years, .Months and .Days - this will prevent you needing to do the calculations yourself.
 
thanks for your reply palusibledump, but i'm afraid if timespan has really properties .Years and .Months.Only .Days I suppose...
 
Back
Top