Ms access MS Access DatePart(“m”和[date])按日期名称列出

Ms access MS Access DatePart(“m”和[date])按日期名称列出,ms-access,criteria,Ms Access,Criteria,是否有一种方法可以在Ms Access中创建一个标准,以按特定(用户输入)月份和年份从日期/时间列获取所有数据 我需要执行以下操作: Like "* " & DatePart("m", [date]) = "aug" AND DatePart("yyyy", [date]) = 2017 DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=

是否有一种方法可以在Ms Access中创建一个标准,以按特定(用户输入)月份和年份从日期/时间列获取所有数据

我需要执行以下操作:

Like "* " & DatePart("m", [date]) = "aug" AND DatePart("yyyy", [date]) = 2017
DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=[year]
DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=[year]
然后,表中包含月份和年份的所有数据都会显示出来


谢谢你的帮助。 我通过以下方法解决了这个问题:

Like "* " & DatePart("m", [date]) = "aug" AND DatePart("yyyy", [date]) = 2017
DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=[year]
DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=[year]
PS.[date]是包含日期/时间数据的列,[month]、[year]是提示用户输入的内容


因此,要求用户输入一个月:她可以输入:Aug或Aug或August,它将得到一个整数形式的月份

使用
格式
而不是
日期部分

Like "* " & Format([date], "mmm") = "Aug" AND DatePart("yyyy", [date]) = 2017
请注意,它是“Aug”而不是“Aug”,如果您真的必须使用“Aug”,则可以:

Like "* " & LCase(Format([date], "mmm")) = "aug" AND DatePart("yyyy", [date]) = 2017

谢谢你的帮助。我通过以下方法解决了这个问题:

Like "* " & DatePart("m", [date]) = "aug" AND DatePart("yyyy", [date]) = 2017
DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=[year]
DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=[year]
PS.[date]是包含日期/时间数据的列,[month]、[year]是提示用户输入的内容


因此,用户被要求输入一个月:她可以输入:Aug或Aug或August,它将得到一个整数形式的月份。

您不应该处理字符串或数字之类的日期,没有例外

因此,将文本条目转换为日期值并创建一个间隔:

>=CDate([Enter Month] & Str([Enter Year])) And <DateAdd("m",1,CDate([Enter Month] & Str([Enter Year])))

=CDate([Enter Month]&Str([Enter Year]),它返回数字,因此
DatePart(“m”,“date])=8
monthname(DatePart(“m”,date))=“August”
,另外
,True
monthname
使用缩写)