Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Service Time - Years & Months Separated

Status
Not open for further replies.

vlfox

Technical User
Oct 13, 2005
40
US
I've been using this formula (by SQL for Enterprise) to get Years of Service as 1 column, like 2.3:

ROUND(CAST(DATEDIFF(MM,((case when PS_EMPLOYMENT.REHIRE_DT IS NOT NULL THEN PS_EMPLOYMENT.REHIRE_DT ELSE PS_EMPLOYMENT.HIRE_DT END)), GETDATE() ) AS DECIMAL(5,2))/ 12,2)

Now I have a request to split Years & Months into 2 columns.

Any tips from the experts?

ThanX !
 
Lets say the employee has worked for 30 months.

30 / 12 = 2.5 years or 2 years 6 months

If we ROUND((30/12),2) we will get 2.5
If we ROUND((30/12),0) we will get 2.0

(2.5 - 2.0) = .5

(.5 * 12) = 6 for the months

Try this formula:

((ROUND(
(DATEDIFF(MM,
(case when PS_EMPLOYMENT.REHIRE_DT IS NOT NULL
THEN PS_EMPLOYMENT.REHIRE_DT
ELSE PS_EMPLOYMENT.HIRE_DT
END),
GETDATE()
)
/ 12),
2)
-
ROUND(
(DATEDIFF(MM,
(case when PS_EMPLOYMENT.REHIRE_DT IS NOT NULL
THEN PS_EMPLOYMENT.REHIRE_DT
ELSE PS_EMPLOYMENT.HIRE_DT
END),
GETDATE()
)
/ 12),
0)
) * 12)

CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining
 
any luck with this?

CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining
 
Just doing a quick test of your formula, I got zeros for all, but haven't been able to spend any time researching it yet.

ThanX for checking !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top