SQL-如何判断日期是否是该月的最后一天? [英] SQL - How to tell if a date is the last day of the month?

查看:736
本文介绍了SQL-如何判断日期是否是该月的最后一天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一些帖子(例如 SQL查询以查找每月的最后一天在SQL中获取月份的最后一天)以获取该月的最后一天,但是有一种方法可以确定日期是否为该月的最后一天?

I have found a few posts (ex. SQL Query to find the last day of the month , Get the last day of the month in SQL) to get the last day of the month, but is there a way to determine if a date is the last day of the month?

例如,如果我有这些日期的列表-

For example, if I had a list of these dates-

8/29/2015   --fail

8/30/2015   --fail

8/31/2015   --pass

9/1/2015    --fail

如何编写查询以确定哪个日期通过/失败?我不能简单地测试是否DAY()= 31,因为月份中的月份天数并不相同。

How could I write a query to determine which dates pass / fail? I could not simply test if DAY() = 31, because the months do not all have the same number of days in them.

推荐答案

如果您使用的是SQL Server 2012或更高版本,请使用 EOMONTH

If you are using SQL Server 2012 or above, use EOMONTH:

SELECT  my_date,
        IsEndOfMonth = IIF(my_date = EOMONTH(my_date), 1, 0) 
FROM    my_table

这篇关于SQL-如何判断日期是否是该月的最后一天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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