Solved

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

Posted on 2014-10-08
1
203 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

914 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

18 Experts available now in Live!

Get 1:1 Help Now