计算某个日期到今天一共有多少年多少月多少日
2009-04-06 01:32
701 查看
比如是07年9月1号,到现在有多少年零几个月零几天这样,不是要他们的总数。是类似按有多少天,再转换成有几年零几个月零几天,就是算工龄一样。
declare @date datetime
set @date = '20070901'
declare @year int, @month int, @day int
set @year = datediff(year, @date, getdate()) - (case when month(@date)>month(getdate()) then 1 when month(@date)=month(getdate()) and day(@date)>day(getdate()) then 1 else 0 end)
set @month = datediff(month, @date, getdate()) - (case when day(@date)>day(getdate()) then 1 else 0 end) - 12*@year
set @day = datediff(day, dateadd(month, (@year*12 + @month), @date), getdate())
select 年 = @year, 月 = @month, 天 = @day
年 月 天
----------- ----------- -----------
X X X
(1 行受影响)
http://topic.csdn.net/u/20090406/00/21d8efda-0644-434b-bb07-9140c3cd26b3.html
declare @date datetime
set @date = '20070901'
declare @year int, @month int, @day int
set @year = datediff(year, @date, getdate()) - (case when month(@date)>month(getdate()) then 1 when month(@date)=month(getdate()) and day(@date)>day(getdate()) then 1 else 0 end)
set @month = datediff(month, @date, getdate()) - (case when day(@date)>day(getdate()) then 1 else 0 end) - 12*@year
set @day = datediff(day, dateadd(month, (@year*12 + @month), @date), getdate())
select 年 = @year, 月 = @month, 天 = @day
年 月 天
----------- ----------- -----------
X X X
(1 行受影响)
http://topic.csdn.net/u/20090406/00/21d8efda-0644-434b-bb07-9140c3cd26b3.html
相关文章推荐
- Js计算指定日期加上多少天、加多少月、加多少年的日期
- 日期的计算多少天 多少月 多少年后 前台通过了ajax调用后台处理获取返回值
- java8 利用java7的date 做一个开始日期到结束日期 计算中间一共隔了多少日期
- Js计算指定日期加上多少天、加多少月、加多少年的日期
- 计算两个日期相隔多少年,多少月,多少天
- php计算两个日期相隔多少年,多少月,多少日的函数
- Js计算指定日期加上多少天、加多少月、加多少年的日期
- Jquery计算指定日期加上多少天、加多少月、加多少年的日期
- 今天开始学Java 给定一个正整数,编写程序计算有多少对质数的和等于输入的这个正整数,并输出结果。
- 从键盘输入一个日期,格式为yyyy-M-d 要求计算该日期与1949年10月1日距离多少天
- Java 计算两个日期直接相差多少天
- 【c++程序】任意给两个日期,计算相差多少天和各自星期几
- javascript 日期 及日期上加多少天,多少月,多少年
- java基础 计算今天距本月最后一天还剩多少天
- SWIFT中计算两个日期间隔多少小时
- 计算格式为YYYY-MM-DD HH:ii:ss的两个时间,相差多少年、多少月、多少日、多少小时、多少分钟、多少秒?
- iOS 计算 日期 距离 当前 系统的日期 相差 多少
- C语言快速计算出一个无符号数一共有多少个“”1”位数的方法
- C#关于日期月天数和一年有多少周及某年某周时间段的计算