SQLTeam.com | Weblogs | Forums

Years and Months


#1

I have a column that shows the number of months of occupancy for a tenant. I would like to run a query that would take this figure and return the number of years and months of occupancy e.g. 6 months would return 0 years and 6 months and 38 months would return 3 years and 2 months. Any help would be appreciated.


#2

Assuming your months column is of data type INTEGER, you can do the following:

SELECT
	monthColumn/12 AS Years,
	monthColumn%12 AS Months
FROM
	YourTable;

#3

Thank you. That worked perfectly.