Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to Calculate AGE?

How to Calculate AGE?

Scheduled Pinned Locked Moved ASP.NET
questiontutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kasi Viswanathan
    wrote on last edited by
    #1

    I have a TextBox in which Date Of Birth is entered...How can i calculate the AGE...Any idea is helpfull. Thanks in Advance...:rose:

    Erasers are for people who are willing to correct their mistakes.

    S J 2 Replies Last reply
    0
    • K Kasi Viswanathan

      I have a TextBox in which Date Of Birth is entered...How can i calculate the AGE...Any idea is helpfull. Thanks in Advance...:rose:

      Erasers are for people who are willing to correct their mistakes.

      S Offline
      S Offline
      Sathesh Sakthivel
      wrote on last edited by
      #2

      Just store the DOB from the text box and use this it would be simpler for you to calculate age in your database server like SELECT DATEDIFF(year, yourbirthdayfield, GETDATE()) AS Age FROM YourTable this will return the a field in your query that has the age.

      SSK. Anyone who says sunshine brings happiness has never danced in the rain.

      P J 2 Replies Last reply
      0
      • S Sathesh Sakthivel

        Just store the DOB from the text box and use this it would be simpler for you to calculate age in your database server like SELECT DATEDIFF(year, yourbirthdayfield, GETDATE()) AS Age FROM YourTable this will return the a field in your query that has the age.

        SSK. Anyone who says sunshine brings happiness has never danced in the rain.

        P Offline
        P Offline
        Paddy Boyd
        wrote on last edited by
        #3

        Why simpler in database? It's pretty much the same in .net code?

        S 1 Reply Last reply
        0
        • P Paddy Boyd

          Why simpler in database? It's pretty much the same in .net code?

          S Offline
          S Offline
          Sathesh Sakthivel
          wrote on last edited by
          #4

          Ok Thanks Paddy Boyd.

          SSK. Anyone who says sunshine brings happiness has never danced in the rain.

          1 Reply Last reply
          0
          • S Sathesh Sakthivel

            Just store the DOB from the text box and use this it would be simpler for you to calculate age in your database server like SELECT DATEDIFF(year, yourbirthdayfield, GETDATE()) AS Age FROM YourTable this will return the a field in your query that has the age.

            SSK. Anyone who says sunshine brings happiness has never danced in the rain.

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            Vri SSK wrote:

            SELECT DATEDIFF(year, yourbirthdayfield, GETDATE()) AS Age

            Common mistake (I've made it myself). Today is 6 Dec 2007. If my birthdate is 5 December 1997 this returns my age as 10. If my birthday is 7 Dec 1997 this also returns my birthdate as 10. DECLARE @myBirthday1 DATETIME DECLARE @myBirthday2 DATETIME SET @myBirthday1 = '5 dec 1997' SET @myBirthday2 = '7 dec 1997' SELECT DATEDIFF(year, @myBirthday1, GETDATE()) SELECT DATEDIFF(year, @myBirthday2, GETDATE()) result: 10 10 FYI the correct way to calculate this is not quite so simple (unfortunately) (case when dateadd(year,datediff(year,[birthdate],getutcdate()),[birthdate])>getutcdate() then datediff(year,[birthdate],getutcdate())-(1) else datediff(year,[birthdate],getutcdate()) end) :-\

            1 Reply Last reply
            0
            • K Kasi Viswanathan

              I have a TextBox in which Date Of Birth is entered...How can i calculate the AGE...Any idea is helpfull. Thanks in Advance...:rose:

              Erasers are for people who are willing to correct their mistakes.

              J Offline
              J Offline
              J4amieC
              wrote on last edited by
              #6
              1. Parse the Text from the textbox into a DateTime. 2) Find the difference between that date and the current date in years.
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups