-- 普通的 SQL 实现 SELECT name, birthday, GETDATE() getdate, CONVERT(VARCHAR(10),GETDATE(),120) todayVarchar, CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120)) todayDateTime, DATEDIFF(YY,birthday,GETDATE()) DateBetween, DATEADD(YY,DATEDIFF(YY,birthday,GETDATE()),birthday) ThisBirthday, DATEADD(YY,DATEDIFF(YY,birthday,GETDATE())+1,birthday) NextBirthday, CASE WHEN CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120))>DATEADD(YY,DATEDIFF(YY,birthday,GETDATE()),birthday) THEN DATEADD(YY,DATEDIFF(YY,birthday,GETDATE())+1,birthday) ELSE DATEADD(YY,DATEDIFF(YY,birthday,GETDATE()),birthday) END newBirthdayStandard, CASE WHEN CONVERT(DATETIME,CONVERT(VARCHAR(10),GETDATE(),120))>DATEADD(YY,DATEDIFF(YY,birthday,GETDATE()),birthday) THEN DATEADD(YY,DATEDIFF(YY,birthday,GETDATE())+1,birthday)+ CASE WHEN DAY(birthday)=29 AND DAY(DATEADD(YY,DATEDIFF(YY,birthday,GETDATE())+1,birthday))=28 THEN 1 ELSE 0 END ELSE DATEADD(YY,DATEDIFF(YY,birthday,GETDATE()),birthday) + CASE WHEN DAY(birthday)=29 AND DAY(DATEADD(YY,DATEDIFF(YY,birthday,GETDATE()),birthday))=28 THEN 1 ELSE 0 END END newBirthdayForeign FROM employees |