当月剩余天数 [英] Number of days left in current month

查看:27
本文介绍了当月剩余天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定月份的剩余天数如何找到当月剩余的天数?如果当前月份是 11 月而今天的日期是 16/11/2016 的示例一个月的天数 - 经过的天数 = ?我想动态地做在我的例子中 30 – 16 = 14

Number of days left in a given month How do I find the number of days left in the current month? Example if current month is November and todays date is 16/11/2016 The Numbers of days in month – Elapse days = ? I want to do it dynamically In my example 30 – 16 = 14

declare @date date 
set @date='16 Nov 2016'
select datediff(day, @date, dateadd(month, 1, @date)) - 16 AS DaysLeft

推荐答案

只需使用 Datepart 函数:

Simply use the Datepart function:

declare @date date
set @date='16 Nov 2016'
select datediff(day, @date, dateadd(month, 1, @date)) - Datepart(DAY,@date) 

这篇关于当月剩余天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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