Calculate a default date value based on todays date

KA3

New member
Local time
Today, 00:39
Joined
Jul 13, 2014
Messages
4
I have a database which stores information relating to club members, which I'm in the middle of giving a bit of a facelift and one thing I want to automate is the calculation of the expiry date.

My memberships expire annually at the end of December and the expiry date is set as a default value within the table properties. This has to be manually changed every September (every new member from then pays for 15 months) to the following December.

Is there a formula I can insert in the defaul value field that will return December the current year if todays date is between January and August, and December next year if todays date is between September and December?
 
Code:
= IIF(Month(Date())>8,DateSerial(Year(Date())+1,12,31),DateSerial(Year(Date()),12,31)
 
Thanks very much, I'll try that tomorrow night :-)
 
Cool solution! Marginally shortened . . .
Code:
=DateSerial(Year(Date())+IIf(Month(Date())>8,1,0),12,31)
 
Just for variety and a little shorter still:
Code:
=DateSerial(Year(Date())-(Month(Date())>8),12,31)

The result of the comparison (Month(Date())>8) is implicitly cast to -1 for True or 0 for False.
 
Well, I guess there's . . .
Code:
="31-Dec-" & Year(Date())-(Month(Date())>8)
 
Not quite a date type though Mark. You've got to do better otherwise Galaxiom will beat you to this. :)
 
Not quite a date type though Mark. You've got to do better otherwise Galaxiom will beat you to this. :)

It is a string but will cast to a date as the default in a date field.


Here is a winner by a character over Mark's
Code:
="31/12/" & Year(Date())-(Month(Date())>8)
;)
 
Applying the datatype rule:
Before Mark gets back, two more characters saved:
Code:
=DateSerial(Year(Now())-(Month(Now())>8),12,31)
 
Clever cheat with Now().
I'm not sure how Mark is going to be able to recover from this one.
 
Naw, I'm busted, outta bullets. Gotta give it to . . .
Code:
=DateSerial(Year(Now())-(Month(Now())>8),12,31)
Also, you guys are total nerds. :)
 

Users who are viewing this thread

Back
Top Bottom