计算两个时间相差年月日的sql

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SELECT CAST(@YearDiff AS NVARCHAR(10)) + '年' + CAST(@MonthDiff AS NVARCHAR(10)) + '月' + CAST(@DayDiff AS NVARCHAR(10)) + '日'
IF (@ToMonth - 1) = 1 OR (@ToMonth - 1) = 3 OR (@ToMonth - 1) = 5 OR (@ToMonth - 1) = 7 OR (@ToMonth - 1) = 8 OR (@ToMonth - 1) = 10 OR (@ToMonth - 1) = 12
计算两个时间相差多少年月日
CREATE PROCEDURE GetDateDiff @fromDate nvarchar(10), @toDate nvarchar(10) AS
DECLARE @YearDiff INTEGER DECLARE @MonthDiff INTEGER DECLARE @DayDiff INTEGER DECLARE @ToMonth INTEGER DECLARE @FromDay INTEGER DECLARE @ToDay INTEGER
BEGIN SET @DayDiff = 31 + @Today - @FromDay SET @MonthDiff = @MonthDiff -1
END ELSE BEGIN
SET @DayDiff = 30 + @Today - @FromDay SET @MonthDiff = @MonthDiff -1 END END ELSE BEGIN SET @DayDiff = @Today - @FromDay 来自百度文库ND
SET @YearDiff = LTRIM(DATEDIFF(yy, @fromDate, @toDate)) SET @MonthDiff = LTRIM(DATEDIFF(mm, @fromDate, @toDate)%12) SET @ToMonth = MONTH(CAST(@toDate AS Datetime)) SET @FromDay = DAY(CAST(@fromDate AS Datetime)) SET @ToDay = DAY(CAST(@ToDate AS Datetime)) IF (@ToDay - @FromDay) < 0 BEGIN
相关文档
最新文档