Jump to content

Saultation changed based on age


tschulte72

Recommended Posts

I recently had a customer who asked for a letter that used an alternate salutation if the member was under 18.

 

ie.

Dear Parent or Gaurdian of John Smith, (if under 18)

or

Dear John Smith, (if over 18)

 

I came up with the following and it seems to work well so I thought I'd share it with anyone who might need something similar.

 

The fuction that calculates the age based on a date uses the format MM/DD/YYYY for the provided birthday.

 

function getAge(birth) {
var today = new Date();
var curr_date = today.getDate();
var curr_month = today.getMonth() + 1;
var curr_year = today.getFullYear();

var pieces = birth.split('/');
var birth_date = pieces[1];
var birth_month = pieces[0];
var birth_year = pieces[2];

if (curr_month == birth_month && curr_date >= birth_date) return parseInt(curr_year-birth_year);
if (curr_month == birth_month && curr_date < birth_date) return parseInt(curr_year-birth_year-1);
if (curr_month > birth_month) return parseInt(curr_year-birth_year);
if (curr_month < birth_month) return parseInt(curr_year-birth_year-1);
}
var age = getAge(Field("Birthday"));
return (age < 18) ? "Dear Parent or Guardian of " + Field("Name") + "," : "Dear " + Field("Name") + ",";

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...