I am using MSSQL Server 2005.
I have this calculation for a field called "CurrentBirthday".
As an example, I have 2 employees
Name:John, DOB:15-09-1988
Name:Bill, DOB:15-09-1989
CurrentBirthday for John shows 15-09-2011
CurrentBirthday for Bill shows 15-09-2012
I can see that this is because John's DOB is on a leap year, but I cannot for the life of my figure out a way around this to mean that they both show 15-09-2012...
My calculation:
CASE WHEN
DATEPART(DY,DATEOFBIRTH) >DATEPART(DY,GETDATE())
THEN
(CASE WHEN
(DATEPART(DD,DATEOFBIRTH) = '29' AND DATEPART(MM,DATEOFBIRTH) = 2)
THEN
(CAST(
(
STR( YEAR( GETDATE() ) ) + '/02/28'
)
AS DATETIME ) )
ELSE
(CAST(
(
STR( YEAR( GETDATE() ) ) + '/' +
STR( MONTH( DATEOFBIRTH ) ) + '/' +
STR( DAY( DATEOFBIRTH ) )
)
AS DATETIME ))
END)
ELSE
(CASE WHEN
(DATEPART(DD,DATEOFBIRTH) = '29' AND DATEPART(MM,DATEOFBIRTH) = 2)
THEN
(CAST(
(
STR( YEAR( DATEADD(YY,1,GETDATE() ) ) ) + '/02/28'
)
AS DATETIME ) )
ELSE
(CAST(
(
STR( YEAR( DATEADD(YY,1,GETDATE() ) ) )+ '/' +
STR( MONTH( DATEOFBIRTH ) ) + '/' +
STR( DAY( DATEOFBIRTH ) )
)
AS DATETIME ))
END)
END
I have this calculation for a field called "CurrentBirthday".
As an example, I have 2 employees
Name:John, DOB:15-09-1988
Name:Bill, DOB:15-09-1989
CurrentBirthday for John shows 15-09-2011
CurrentBirthday for Bill shows 15-09-2012
I can see that this is because John's DOB is on a leap year, but I cannot for the life of my figure out a way around this to mean that they both show 15-09-2012...
My calculation:
CASE WHEN
DATEPART(DY,DATEOFBIRTH) >DATEPART(DY,GETDATE())
THEN
(CASE WHEN
(DATEPART(DD,DATEOFBIRTH) = '29' AND DATEPART(MM,DATEOFBIRTH) = 2)
THEN
(CAST(
(
STR( YEAR( GETDATE() ) ) + '/02/28'
)
AS DATETIME ) )
ELSE
(CAST(
(
STR( YEAR( GETDATE() ) ) + '/' +
STR( MONTH( DATEOFBIRTH ) ) + '/' +
STR( DAY( DATEOFBIRTH ) )
)
AS DATETIME ))
END)
ELSE
(CASE WHEN
(DATEPART(DD,DATEOFBIRTH) = '29' AND DATEPART(MM,DATEOFBIRTH) = 2)
THEN
(CAST(
(
STR( YEAR( DATEADD(YY,1,GETDATE() ) ) ) + '/02/28'
)
AS DATETIME ) )
ELSE
(CAST(
(
STR( YEAR( DATEADD(YY,1,GETDATE() ) ) )+ '/' +
STR( MONTH( DATEOFBIRTH ) ) + '/' +
STR( DAY( DATEOFBIRTH ) )
)
AS DATETIME ))
END)
END