将月份转换为年份 [英] convert months to year
本文介绍了将月份转换为年份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
如何将月份数转换为年份数?
例如:如果我有36个月,那么我应该得到3年..有可能吗?
如果是这样,请建议我...
谢谢"
hello everyone,
How can i convert number of months to number of year??
e.g: if i have 36 months then i should get 3 year.. is it possible?
if so please suggest me...
"Thanking you"
推荐答案
declare @year int
declare @months int
set @months=36
set @year=@months/12
print @year
在上述情况下,@year是一个整数,因此即使您将45用作月份,您也将获得3的输出.
就像
0-11输出为0
12-23输出为1
24-35输出为2
36-47输出为3
更新的解决方案
In the above case, @year is an integer, so even if you pass 45 as month, you will get 3 as output.
So it will be like
0-11 out put is 0
12-23 output is 1
24-35 output is 2
36-47 output is 3
Updated solution
declare @year int
declare @months int
set @months=45
set @year=@months/12
set @months=@months%12
print cast(@year as varchar(100))+' years '+cast(@months as varchar(100))+ ' months '
这会给我
3年9个月
this wil give me
3 years 9 months
这篇关于将月份转换为年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文