Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
hanshuman10
Starting Member
2 Posts |
Posted - 2012-05-02 : 19:22:36
|
| Hi I have the date in 3 different fields dobday,dob month and dob year. I need to get the dob field and then the age field how can i do thisThanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-02 : 20:55:01
|
SELECT DATEADD(MONTH, 12 * dobYear + dobMonth - 22801, dobDay - 1) N 56°04'39.26"E 12°55'05.63" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-05-03 : 10:17:18
|
| orselect dateadd(year,dobYear -1900,dateadd(month,dobMonth -1,dateadd(day,dobDay -1,0)))MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-03 : 14:44:45
|
for calculating age you can use logic likeCASE WHEN MONTH(dob)> MONTH(GETDATE()) OR (MONTH(dob)= MONTH(GETDATE()) AND DAY(dob)> DAY(GETDATE())) THEN DATEDIFF(yy,dob,GETDATE()) ELSE DATEDIFF(yy,dob,GETDATE()) -1END ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
hanshuman10
Starting Member
2 Posts |
Posted - 2012-05-03 : 19:07:15
|
quote: Originally posted by SwePeso SELECT DATEADD(MONTH, 12 * dobYear + dobMonth - 22801, dobDay - 1)Hey Thanks That worked N 56°04'39.26"E 12°55'05.63"
|
 |
|
|
|
|
|
|
|