×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Service Time - Years & Months Separated

Service Time - Years & Months Separated

Service Time - Years & Months Separated

(OP)
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 !

RE: Service Time - Years & Months Separated

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

RE: Service Time - Years & Months Separated

any luck with this?

CharlesCook.com
ADP - PeopleSoft - SAP
ReportSmith - Crystal Reports - SQR - Query - Access
Reporting - Interfaces - Data Mining

RE: Service Time - Years & Months Separated

(OP)
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 !

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close