Results 1 to 3 of 3

Thread: Converting between numbers and date

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    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

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    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

  3. #3
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Converting between numbers and date

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         MaskedTextBox1.Text = "01-21-1990" 'example
    5.     End Sub
    6.  
    7.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    8.         Dim dtDOB As Date
    9.         Dim myTimeSpan As TimeSpan
    10.  
    11.         Date.TryParse(MaskedTextBox1.Text, dtDOB)
    12.         myTimeSpan = Now.Subtract(dtDOB)
    13.  
    14.         '~~~ Here based on the seletion of item from the Combobox, display whatever you want
    15.         Debug.Print("Days = " & myTimeSpan.TotalDays)
    16.         Debug.Print("Years = " & myTimeSpan.TotalDays / 365)
    17.         Debug.Print("Weeks = " & myTimeSpan.TotalDays / 52)
    18.         Debug.Print("Months = " & myTimeSpan.TotalDays / 12)
    19.     End Sub
    20. 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
  •  



Click Here to Expand Forum to Full Width