How to Calculate AGE?
-
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.
-
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.
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.
-
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.
Why simpler in database? It's pretty much the same in .net code?
-
Why simpler in database? It's pretty much the same in .net code?
Ok Thanks Paddy Boyd.
SSK. Anyone who says sunshine brings happiness has never danced in the rain.
-
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.
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)
:-\ -
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.