Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Dates

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 11th, 2013, 11:54 AM
tschulte72 tschulte72 is offline
Forum n00b
 
Join Date: Mar 2013
Posts: 2
Default Saultation changed based on age

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.

Code:
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") + ",";
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 11:52 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.