IIF语句综观月

问题描述 投票:1回答:1

我想创建一个IIF语句来计算,当一个孩子的预期离开日期。

例如,谁是31/08之前出生的孩子,预计4年后离开幼儿园,该日期,预计5年后离开后,谁是出生的孩子。

现在我所要做的是问一个IIF语句看起来出生日期,并决定是否计算为4年或5年。但是我一直运行到与我使用的是代码问题

= IIf([Date of Birth]>#31/08/0000# , =DateAdd("yyyy",4,[Date of Birth]) , =DateAdd("yyyy",5,[Date of Birth]))

因为有多个孩子的出生日期不同。需要有一种方法,仅在几个月专门研究。

编辑:原来,是不是我的老板需要,他需要的东西基本上是当孩子从幼儿园时即围绕新学期辊和孩子是4岁离开来显示。如果孩子在九月前出生,他可用的是,今年开始上学。如果他不是孩子是适用于学校开始在明年九月份。而现在我不知道该怎么做,因为我做一个IIF函数的尝试彻底失败。任何人都可以帮忙吗?

ms-access-2016
1个回答
0
投票

试着用:

=DateAdd("yyyy", IIf([Date of Birth] > DateSerial(Year([Date of Birth]), 8, 31), 4, 5), [Date of Birth])

编辑1:

你可以使用像使用DateAdd:

=IIf(DateAdd("yyyy", 4, [Date of Birth]) < DateSerial(Year(Date()), 9, 1), "Start school this year", "Postpone school start")

编辑2:

或者你可以计算出9月1日的孩子们的年龄:

AgeAtSeptember: Age([Date of Birth], DateSerial(Year(Date()), 9, 1))

使用此功能:

' Returns the difference in full years from DateOfBirth to current date,
' optionally to another date.
' Returns zero if AnotherDate is earlier than DateOfBirth.
'
' Calculates correctly for:
'   leap years
'   dates of 29. February
'   date/time values with embedded time values
'   any date/time value of data type Date
'
' DateAdd() is used for check for month end of February as it correctly
' returns Feb. 28th when adding a count of years to dates of Feb. 29th
' when the resulting year is a common year.
'
' 2015-11-24. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function Age( _
    ByVal DateOfBirth As Date, _
    Optional ByVal AnotherDate As Variant) _
    As Integer

    Dim ThisDate    As Date
    Dim Years       As Integer

    If IsDateExt(AnotherDate) Then
        ThisDate = CDate(AnotherDate)
    Else
        ThisDate = Date
    End If

    ' Find difference in calendar years.
    Years = DateDiff("yyyy", DateOfBirth, ThisDate)
    If Years > 0 Then
        ' Decrease by 1 if current date is earlier than birthday of current year
        ' using DateDiff to ignore a time portion of DateOfBirth.
        If DateDiff("d", ThisDate, DateAdd(IntervalSetting(DtInterval.dtYear), Years, DateOfBirth)) > 0 Then
            Years = Years - 1
        End If
    ElseIf Years < 0 Then
        Years = 0
    End If

    Age = Years

End Function
© www.soinside.com 2019 - 2024. All rights reserved.