如果我有1到31之间的整数值(@dayOfMonth
),我如何确定当月剩余时间或下一个月的那一天的下一个日期月?
如果@dayOfMonth
大于该月的有效天数,则结果应为该月的最后一天。例如,如果@dayOfMonth
为31,今天为4/15/17,我预计结果为4/30/17。
这些是我期望的以下值的结果:
@testDate = 4/15/17 and @dayOfMonth = 31, result should be 4/30/17
@testDate = 4/15/17 and @dayOfMonth = 30, result should be 4/30/17
@testDate = 4/15/17 and @dayOfMonth = 25, result should be 4/25/17
@testDate = 4/15/17 and @dayOfMonth = 7, result should be 5/7/17
@testDate = 4/15/17 and @dayOfMonth = 15, result should be 5/15/17
@testDate = 1/31/17 and @dayOfMonth = 31, result should be 2/28/17
@testDate = 12/25/15 and @dayOfMonth = 5, result should be 1/5/18
答案 0 :(得分:0)
我认为这可以解释所有与月份相关的关注条件。似乎罗嗦但它给出了预期的结果。注意:user
和EOMONTH
都至少需要SQL 2012。
DATEFROMPARTS