按日期名称

时间:2017-08-24 15:35:04

标签: 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])=[year]

PS。 [date]是具有日期/时间数据和[月]的列,[年]是提示用户输入的内容。

因此要求用户提供一个月:她可以输入:8月或8月或8月,它会将月份作为整数。

3 个答案:

答案 0 :(得分:0)

使用Format代替DatePart

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

请注意,它是“八月”不是“八月”,如果你真的必须使用“八月”,那么这样做:

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

答案 1 :(得分:0)

感谢您的帮助。我通过以下方式解决了这个问题:

DatePart("m",[date])=Month(DateValue(Left([Month],3) & "-01-2017")) And DatePart("yyyy",[date])=[year]

PS。 [date]是具有日期/时间数据和[月]的列,[年]是提示用户输入的内容。

因此要求用户提供一个月:她可以输入:8月或8月或8月,它会将月份作为整数。

答案 2 :(得分:0)

你永远不应该处理像字符串,数字,没有例外的日期。

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

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

在查询中指定月份和年份参数为文本和整数。

相关问题