如何将日期列更新为该月的最后一天 [英] How to update date column to be last day of the month

查看:101
本文介绍了如何将日期列更新为该月的最后一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如何将整列的值更新到该月的最后一天。

例如。目前是2015-09-01。更新至2015-09-30。

只是一个FYI - 我有超过500个日期需要更新。

Hi,
How do I update the value of the entire column to the last day of the month.
for example. Currently its 2015-09-01. Update to 2015-09-30.
Just an FYI - I have more than 500 dates to update.

推荐答案

如果所有行值都包含某个月的第一天,只需添加一个月,然后返回一天。所以类似

If all the row values contain the first day of some month, just add one month and go back one day. So something like
UPDATE TableName
SET DateColumn = DATEADD(month, 1, DateColumn ) - 1;



有关详细信息,请参阅 DATEADD [ ^ ]


由于您使用的是SQL 2012,因此可以使用新的 EOMONTH [ ^ ]功能:

Since you're using SQL 2012, you can use the new EOMONTH[^] function:
UPDATE YourTable
SET YourColumn = EOMONTH(YourColumn)


这篇关于如何将日期列更新为该月的最后一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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