Date calc

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

For once, this isn't pressing but I am curious.

This formula works fine. What is the purpose of the NOW
() statement at the end of the line?

=Iif([member status]="deceased" Or IsNull
([birthday])," ",Year(Now())-Year([birthday])+(DateSerial
(Year(Now()),Month([birthday]),Day([birthday]))>Now()))
 
Date() returns the current date, but without a time component. Now() returns
the current date, including a time component.

The Now() at the end of the statement is comparing what precedes it with
today's date. In this specific case, it's being used to determine whether to
subtract 1 from the result of Year(Now()-Year([birthday]).

DateSerial(Year(Now()),Month(birthday),Day(birthday))
....returns the birthday anniversary in the current year.

(DateSerial(Year(Now()),Month(birthday),Day(birthday))>Now())
....compares this birthday anniversary to today's date (using Now()), and
returns -1 (True) if the birthday anniversary is later than today. If not,
it returns 0 (False).

So the whole thing says:
Subtract my birth year from the current year, and then subtract 1 from
the result if the birthday anniversary has already passed.

I don't see any reason for using Now() - Date() would have done just as
well. Also (although that may be what you want), usually people consider
themselves a year older on the day of their birthday, so >Now() should be
=Now(). So, the whole thing should look like this:

=IIf([member status]="deceased" Or IsNull([birthday]),"
",Year(Date())-Year([birthday])+(DateSerial(Year(Date()),Month([birthday]),D
ay([birthday]))>=Date()))

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html


For once, this isn't pressing but I am curious.

This formula works fine. What is the purpose of the NOW
() statement at the end of the line?

=Iif([member status]="deceased" Or IsNull
([birthday])," ",Year(Now())-Year([birthday])+(DateSerial
(Year(Now()),Month([birthday]),Day([birthday]))>Now()))
 
Thanks Graham. I'm sure others will benefit from your
through explanation.
David S.
-----Original Message-----
Date() returns the current date, but without a time component. Now() returns
the current date, including a time component.

The Now() at the end of the statement is comparing what precedes it with
today's date. In this specific case, it's being used to determine whether to
subtract 1 from the result of Year(Now()-Year ([birthday]).

DateSerial(Year(Now()),Month(birthday),Day(birthday))
....returns the birthday anniversary in the current year.

(DateSerial(Year(Now()),Month(birthday),Day(birthday))
Now())
....compares this birthday anniversary to today's date (using Now()), and
returns -1 (True) if the birthday anniversary is later than today. If not,
it returns 0 (False).

So the whole thing says:
Subtract my birth year from the current year, and then subtract 1 from
the result if the birthday anniversary has already passed.

I don't see any reason for using Now() - Date() would have done just as
well. Also (although that may be what you want), usually people consider
themselves a year older on the day of their birthday, so
Now() should be
=Now(). So, the whole thing should look like this:

=IIf([member status]="deceased" Or IsNull([birthday]),"
",Year(Date())-Year([birthday])+(DateSerial(Year(Date ()),Month([birthday]),D
ay([birthday]))>=Date()))

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd- 0764559036.html


For once, this isn't pressing but I am curious.

This formula works fine. What is the purpose of the NOW
() statement at the end of the line?

=Iif([member status]="deceased" Or IsNull
([birthday])," ",Year(Now())-Year([birthday])+ (DateSerial
(Year(Now()),Month([birthday]),Day([birthday]))>Now()))


.
 
Back
Top