Results 1 to 4 of 4

Thread: How to display date and calculate age

  1. #1
    jpdbay is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Feb 2006
    Posts
    31
    Reputation
    102

    How to display date and calculate age

    Hi,

    I'm capturing date of birth in DateTimePicker ("MM/DD/YYYY" format).
    1. How do I display the date into "MM/DD/YYYY"?

    2. How do I calculate age from the DateTimePicker using "MM/DD/YYYY" format?

    Anyone, with ideas or code of sample will be much appreciated. Thanx

    Rgds,
    jpdbay
    Last edited by JuggaloBrotha; 03-22-2006 at 1:19 AM.

  2. #2
    programmerskills is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Jul 2005
    Posts
    30
    Reputation
    109
    Hey,

    Please see my Inline Comments:

    I'm capturing date of birth in DateTimePicker ("MM/DD/YYYY" format).
    1. How do I display the date into "MM/DD/YYYY"?

    Jay- a. Add a DatetimePicker control on your form.
    b. Go to the property Window.
    c. In CustomFormat Property add "MM/dd/yyy"
    d. In Format Choose Custom Option.
    Your DateTimePicker will Show DateTime value as "MM/dd/yyy"
    2. How do I calculate age from the DateTimePicker using "MM/DD/YYYY" format?

    Jay - I have copied a very simple code just to show you how to calculate .
    But u can still Implement a better way
    [code]
    Dim dtNow AsDate
    dtNow = DateTime.Now.Date ' Current Date
    Dim Age AsInteger' Number of days.
    Dim dob AsDate' Date Of Birth Entered By User
    dob = DateTimePicker1.Value.Date ' Collect Date of Birth
    Age = dob.Subtract(dtNow).Days ' Get the Number of days.
    ' Do u r own calculations how want to Represent Age
    [code]

    - Jay

    Jay Kavimandan

  3. #3
    jpdbay is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Feb 2006
    Posts
    31
    Reputation
    102
    hi Jay,

    Thanx 4ur comment n comment. Anyway, the formula for Age in the code should be:
    Age = dtNow.Subtract(dob).Days ' Get the Number of days.
    else it rtns -ve value.

    Thanx 4ur guidance.

    rgds,
    jpdbay

    I

  4. #4
    programmerskills is offline VB.NET Forum Enthusiast
    .NET Framework
    .NET 1.1 (VS 2003)
    Join Date
    Jul 2005
    Posts
    30
    Reputation
    109
    Hey,

    Well If that solves ur Query then its Fine

    - Jay

    Jay Kavimandan

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking