|
-
Sep 21st, 2010, 06:39 AM
#1
Thread Starter
Frenzied Member
Converting between numbers and date
Say i have the following setup

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
-
Sep 21st, 2010, 06:48 AM
#2
Thread Starter
Frenzied Member
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
-
Sep 21st, 2010, 07:24 AM
#3
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
...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|