Link to home
Start Free TrialLog in
Avatar of tanj1035
tanj1035

asked on

how to calculate the date range and display it in years+months

Hi,

How to calculate  the length of the employment and display it in a format like 1 years 8 months.  [customeremployementstartdate]

The query will be something like

Open in new window

select getdate()- customeremploymentstartdate as length of the employment
from tblcustomers

Open in new window

[customeremployementstartdate] is in a format like 2012-12-13 09:00:00.000


Thank you very much
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

SELECT
    FLOOR(DATEDIFF(DAY, customeremploymentstartdate, GETDATE()) / 30.412 / 12) AS employment_years ,
    FLOOR(DATEDIFF(DAY, customeremploymentstartdate, GETDATE()) / 30.412 % 12) AS employment_months,
    *
FROM tblcustomer
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.