Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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:

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...

Edited by PlausiblyDamp
  • Administrators
Posted
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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...