Solved

Sql Server DATEDIFF - how to convert months to  YEARS , Months

Posted on 2014-10-08
1
199 Views
Last Modified: 2014-10-08
How do you convert months to  Years and Months?

SELECT DATEDIFF(month, '2003-12-31 23:59:59.9999999'
, '2006-01-01 00:00:00.0000000');    -- returns 25 months

I need to return    2 Years  and 1 Month
0
Comment
Question by:JElster
1 Comment
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 40368908
SELECT CAST(DATEDIFF(month, '2003-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000')
    / 12 AS varchar(3)) + ' year(s) and ' +
    CAST(DATEDIFF(month, '2003-12-31 23:59:59.9999999' , '2006-01-01 00:00:00.0000000') % 12
    AS varchar(2)) + ' month(s)';
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now