how to get the number on months between two dates in sql server 2005

前端 未结 4 1794
余生分开走
余生分开走 2021-01-13 08:49

I have a column in my sql server 2005 table that should hold the number of months an employee has been in service.

Since I also have the date the employee was engage

4条回答
  •  梦毁少年i
    2021-01-13 09:34

    Same approach as gbn, but with less keystrokes :-)

    SELECT 
        DATEDIFF(MONTH, DateEngaged, GETDATE()) +
        CASE 
            WHEN DAY(DateEngaged) < DAY(GETDATE())
            THEN 1 
            ELSE 0 
        END
    

提交回复
热议问题