在SQL Server中基于天数不计算年,月和天数 [英] Calculating no of years,month and days on basis of no of days in sql server

查看:77
本文介绍了在SQL Server中基于天数不计算年,月和天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我的日子没有:547.现在,我必须从这天数中计算出天数,月数和年数.


谢谢
莫哈末Wasif

Hi All,


I have no of days as :547. Now I have to calculate no of days,months and years from this no of days.


Thanks
Mohd. Wasif

推荐答案

除非您至少知道开始或结束的年份,否则您无法准确地做到这一点.
两者之间可能会有leap年,因此,除非您知道底数,否则您将永远无法获得正确的结果.

如果您想近似一下,只需将天数乘以365,就可以得到年份.
然后将剩余部分除以30.这将给您几个月,剩余部分为几天.
You cannot do this with accuracy unless you know at least the start or end year.
There could be leap years in between and thus you can never get a correct result unless you know a base.

If you want an approximation just dive the number of days by 365. That will give you the year.
Then divide the remained by 30. That will give you months and the remainder are days.


这篇关于在SQL Server中基于天数不计算年,月和天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆