简体   繁体   English

SQL从日期中扣除一个月,但保持顺序正确

[英]SQL deduct one month from a date but keep the order correct

The title is probably worded poorly but what I want to have is say I do this 标题可能措辞不佳,但我想说的是

SELECT DATEADD(month,-1,'4/30/2019')

Instead of getting 3/30/2019 I want 3/31/2019, how do we do this? 而不是获得2019年3月30日我想要2019年3月31日,我们如何做到这一点?

If you want the last day of the previous month: 如果要上个月的最后一天:

SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, '2019-04-30'), -1)

See the demo . 参见演示
Result: 结果:

2019-03-31

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM