Thursday, July 28, 2011

SQL Age Calculation (การคำนวณอายุ)


Declare @bDate  DateTime
set @bDate = ’1976-08-04′
Select ABS(DATEDIFF(month, @bDate, getdate()))/12 as[YEAR] , ABS(DATEDIFF(month, @bDate, getdate()))%12 as [MONTH]
Output:
YEAR    MONTH
34        4

No comments:

Post a Comment