Expand my Community achievements bar.

Creating a form... need help with calculating value based on multiple date ranges

Avatar

Former Community Member

I am trying to create a registration form for a conference.  In this form, I want to offer multiple discounts based on date of registration (basically an "early bird" program).  I am not sure of the best way to do this.  I have a form total which basically sums all areas of registration options.  Once this total is established, the total should have a discount applied based on the date of submission; prior to May 31 = 15%;  June 1 - June 30 = 10%, July 1 - July 31 = 5%; after July 31, no discount is applied.  I can't figure this out.  Can anyone help? 

7 Replies

Avatar

Level 8

Put this in the calculate event of your total field (FormCalc):

var myDisplayPattern = "MMMM D, YYYY" //The display pattern for your date of submission field
var tot = sum(NumericField2, NumericField3) //All the fields you're totalling
var submissionDate = Date2Num(DateOfSubmission,myDisplayPattern)
var submissionYear = Right(DateOfSubmission, 4) //takes the year from the DatOfSubmission field, replace with any year you need (ex. "2012")

if (submissionDate - Date2Num(Concat("May 31, ",submissionYear),myDisplayPattern)<=0)then //May 31st and prior
tot-(tot*.15)
elseif (submissionDate<=Date2Num(Concat("June 30, ",submissionYear), myDisplayPattern)) then //June 1 to June 30
tot-(tot*.10)
elseif (submissionDate<=Date2Num(Concat("July 31, ",submissionYear), myDisplayPattern)) then //July 1 to July 31
tot-(tot*.05)
else
tot //All other dates
endif

This is assuming your submission date field has the display pattern "MMMM D, YYYY" (ex. January 1, 2013).

It assumes all your dates are of the same year as your submission date.

Here's a sample form I whipped up.

Kyle

Avatar

Former Community Member

Thanks, Kyle.  It was.  But no matter what date I put in the form, it applied the 15%?  I made updates to the forumula you gave (only to accurately reflect names of objects in the sheet).  This is what i have...

topmostSubform.Page2.TotalCostIDCE2014::calculate - (FormCalc, client)

var myDisplayPattern = "MMMM D, YYYY" //The display pattern for your date of submission field

var tot = TotalPreDiscount //All the fields you're totalling

var submissionDate = Date2Num(Page1.DateofSubmission, myDisplayPattern)

var submissionYear = "2013" //takes the year from the DatOfSubmission field, replace with any year you need (ex. "2012")

if (submissionDate - Date2Num(Concat("May 31, ",submissionYear),myDisplayPattern)<=0)then //May 31st and prior

tot-(tot*.15)

elseif (submissionDate<=Date2Num(Concat("June 30, ",submissionYear), myDisplayPattern)) then //June 1 to June 30

tot-(tot*.10)

elseif (submissionDate<=Date2Num(Concat("July 31, ",submissionYear), myDisplayPattern)) then //July 1 to July 31

tot-(tot*.05)

else

tot //All other dates

endif

Avatar

Level 8

Did you try the sample form I posted?

I put in June 1, 2013 as the submission date and 50 in both numeric fields to get 90 in total, which is the 10% discount required between June 1 and June 30...

Kyle

Avatar

Former Community Member

Using your form, I get 85 with June 1 date?  screenshot.jpg

Avatar

Level 8

Oh, you need to enter a year. Display pattern "MMMM D, YYYY" (ex. January 1, 2013).

Kyle

Avatar

Former Community Member

Still not working.  Your form isn't working on my desktop either.  Even with the entire date typed in MMMM D, YYYY.   We will have to outsource the form creation.  Thanks anyway.