sql通过查询一个指定日期(如2018-02-23),可以知道指定日期所在月份剩余天数和剩余周末天数

DECLARE @date DATE='' 
DECLARE @date_month_end_day DATE =''
SET @date='2018-02-23'
SET @date_month_end_day=DATEADD(DAY,-1,DATEADD(MONTH,1,DATEADD(DAY,1-DAY(@date),@date)))
--指定日期所在月份剩余天数和剩余周末天数
DECLARE @i INT = DAY(DATEADD(DAY,1,DAY(@date)))
DECLARE @j INT =0
WHILE @i <= DAY(@date_month_end_day)
BEGIN
    IF  DATEPART(WEEKDAY,CAST(CAST(YEAR(@date) AS VARCHAR(4))+'-'+CAST(MONTH(@date) AS VARCHAR(2))+'-'+CAST(@i AS VARCHAR(2)) AS DATE)) NOT BETWEEN 2 AND 6
    SET @j=@j+1
    SET @i=@i+1
END
SELECT @date AS 输入的日期,DATEDIFF(DAY,@date,@date_month_end_day) AS 剩余天数,@j AS 剩余周末天数
sql通过查询一个指定日期(如2018-02-23),可以知道指定日期所在月份剩余天数和剩余周末天数_第1张图片

你可能感兴趣的:(java)