Here is my solution for creating a list of people’s birthdays so that the display expression tells me how old they are going to be on their next birthday. This solution also allows me to sort the birthdays in the Attribute Browser (AB) so that I can see the birthdays by month in the correct calendar order and that birthdays within any given month are sorted by the day of the month.
There are no name attributes as the name of the person in in the $Name
attribute.
Sorry if this is somewhat convoluted!
My attributes are:
$DOB
is a date attribute
$Age
is a number attribute
$AgeThisYear
is a number attribute
$BirthMonthMo
is a string attribute
$BirthDayD
is a string attribute
$BirthMonthMM
is a string attribute
$BirthDayMonthAB
is a string attribute
Edict Rules
$Age=years($DOB,date("today"));
$AgeThisYear=$Age+1;
$BirthMonthMo=$DOB.format("M0");
$BirthDayD=$DOB.format("D");
$BirthMonthMM=$DOB.format("MM");
$BirthDayMonthAB=$BirthMonthMo+" "+$BirthMonthMM;
Display Expression Rule
$Name+" Turns "+$AgeThisYear+" on "+$DOB.format("D M")
Prototype
I have one prototype to set birthdays, p_birthday
.
Logic
I ended up separating all parts of the $DOB
. This is because I realised that I needed them for different parts of different views that I wanted.
$AgeThisYear
was needed as the $Age
gives me their current age not the age they will be on their next birthday. This simply adds 1
to their $Age
. This is then used in the $DisplayExpression
of prototype p_birthday
. It looks like this in outline view:
Attributes Explained
$DOB
is the Date of birth of the person.
$Age
calculates the age as a number using $Age=years($DOB,date("today"));
ie “83”.
$BirthMonthMo
returns the month of the DOB as a number ie “08" using, $BirthMonthMo=$DOB.format("M0”);
. The “M0” is needed to give a leading zero to single digit months so that the months display in order in the AB.
$BirthMonthMM
returns the month of the DOB as a string ie “August” using $BirthMonthMM=$DOB.format("MM”);
. Again for us in the AB.
$BirthDayD
returns the DOB day of the month as a number ie “12” using, $BirthDayD=$DOB.format(“D”);
. The “D” is important as it add a leading zero to the day of month single digits. Again for use in the AB to display the day of the month in calendar order.
$BirthDayMonthAB
gives me the month value as a string value in the format, “08 August" using $BirthDayMonthAB=$BirthMonthMo+" "+$BirthMonthMM;
. This attribute is needed to sort the birthdays by month in calendar order.
I wanted to be able to use the AB to sort the birthdays in order of month and then by order of day. This was done with the following setup in the AB:
The query in the AB simply removes any entries that have no $DOB
value by using, !$DOB=="never"
As ever, if there’s a better way of doing this please let me know.
Thanks for all you help in getting this sorted!