如何从日期列列表中检索当前月份日期 [英] How to retrieve current month date from list of date columns

查看:140
本文介绍了如何从日期列列表中检索当前月份日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子上有日期列表,

i想要仅检索当前月份日期



for ex



12/11/2015

29/11/2015

01/11/2015

2015年1月12日

21/10/2015

21/11/2016



来自这些清单我要预订的日期



12/11/2015

29/11/2015

01 / 11/2015



仅在本月日期我想要检索

i have list of dates in my table ,
i want to retrieve current month dates only

for ex

12/11/2015
29/11/2015
01/11/2015
01/12/2015
21/10/2015
21/11/2016

from these list of dates i want to retrieve

12/11/2015
29/11/2015
01/11/2015

only this month dates i want retrieve

推荐答案

使用MONTH非常简单)函数和GETDATE():



That is pretty simple using MONTH() function and GETDATE():

Select colDate
from #table_name
where MONTH ( colDate ) = MONTH(GETDATE())







这是一个完整的工作样本:






Here is a complete working sample:

create table #table_name
(
   colDate date
)

INSERT INTO #table_name(colDate) VALUES('11-12-2015')

INSERT INTO #table_name(colDate) VALUES('11-29-2015')

INSERT INTO #table_name(colDate) VALUES('11-01-2015')

INSERT INTO #table_name(colDate) VALUES('12-01-2015')

INSERT INTO #table_name(colDate) VALUES('10-21-2015')

INSERT INTO #table_name(colDate) VALUES('11-21-2016')



Select MONTH(colDAte),colDate
from #table_name
where MONTH ( colDate ) = MONTH(GETDATE())

DROP table #table_name


SELECT MyDateField
FROM MYTable
WHERE MONTH(MyDateField) = MONTH(GETDATE())


这篇关于如何从日期列列表中检索当前月份日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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