Converting between numbers and date
Say i have the following setup
http://img535.imageshack.us/img535/3655/67557494.png
What i am trying to do is, when the user clicks on the 'calculate age ' button it must calculate the age and display the result based upon the selection in the combobox i.e if 'Days' are selected then it must display in days, if weeks are selected then it must display in weeks..etc
Similarly when the user clicks on the 'convert to date' button , it must subtract the given days(or weeks or months or years) from Todays date and set it to the maskedbox
Re: Converting between numbers and date
I also actually need to use the same maskedbox(by changing its mask) for Date Mode or Numeric mode, didn't mention it previously so as not to make it complex
Re: Converting between numbers and date
vb Code:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MaskedTextBox1.Text = "01-21-1990" 'example
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dtDOB As Date
Dim myTimeSpan As TimeSpan
Date.TryParse(MaskedTextBox1.Text, dtDOB)
myTimeSpan = Now.Subtract(dtDOB)
'~~~ Here based on the seletion of item from the Combobox, display whatever you want
Debug.Print("Days = " & myTimeSpan.TotalDays)
Debug.Print("Years = " & myTimeSpan.TotalDays / 365)
Debug.Print("Weeks = " & myTimeSpan.TotalDays / 52)
Debug.Print("Months = " & myTimeSpan.TotalDays / 12)
End Sub
End Class
...:wave: