MS Access-第四个生日之后的日期 [英] MS Access - Date after fourth birthday
问题描述
希望这是一个相对简单的查询.
Hopefully a relatively simple query.
我正在使用MS Access,我正试图从他们的生日4月生日后的9月1日算起.
I'm using MS Access, I'm trying to work out from the date of birth, the 1st of September after their 4th birthday.
因此,如果我的DOB是02/07/2015,它将返回01/09/2019.
So if my DOB was 02/07/2015, it would return 01/09/2019.
如果我的DOB是2015年3月9日,它将返回01/09/2020.
If my DOB was 03/09/2015, it would return 01/09/2020.
任何帮助将不胜感激.
谢谢
推荐答案
您可以定义一个函数,例如:
You could define a function such as:
Function SchoolStart(dob As Date) As Date
If DateSerial(Year(dob), 9, 1) < dob Then
SchoolStart = DateSerial(Year(dob) + 5, 9, 1)
Else
SchoolStart = DateSerial(Year(dob) + 4, 9, 1)
End If
End Function
示例:
?SchoolStart(#2015-07-02#)
01/09/2019
?SchoolStart(#2015-09-02#)
01/09/2020
请注意,根据当前函数逻辑,在9月1日生日是 ,该孩子在该年的学校就读中:
Note that, with the current function logic, a birthday on the 1st September includes the child in that year's school intake:
?SchoolStart(#2015-09-01#)
01/09/2019
或者,如果您想直接在表单的查询或控制源中使用以上逻辑,则可以使用以下内联表达式:
Or, if you want to use the above logic directly in a query or control source for a form, you could use the following inline expression:
DateSerial(Year([YourDate])+IIf(DateSerial(Year([YourDate]),9,1)<[YourDate],5,4),9,1)
在这里,[YourDate]
是包含要执行计算的日期的字段.
Here, [YourDate]
is the field which contains the date on which the calculation is to be performed.
这篇关于MS Access-第四个生日之后的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!