Jump to content

End Date Field Automatically Populating to One Year from Start Date Entered


Recommended Posts

To preface, this will be used on a coupon that currently has a start date and an end date field for the user to choose. The client has asked for end dates to automatically be one year from the start date that is selected with the end date being a required but hidden field for the user. Can. rule be written so the end date field can be automatically populated with a date that is one year from the start date that the user selects? The field names in my flat file data are "OfferStartDate" and "OfferStartDate".

 

Thanks!

Link to comment
Share on other sites

var myDate = DateFromString(Field("OfferStartDate"));
myDate.setFullYear(myDate.getFullYear() + 1);
return FormatDate(myDate, "mm/dd/yyyy");

You can format the resulting date however you want in the last line.  (Refer to the Rules Guide.)

Link to comment
Share on other sites

  • 1 month later...

@Dan Korn this rule isn’t working that you supplied

var myDate = DateFromString(Field("OfferStartDate"));
myDate.setFullYear(myDate.getFullYear() + 1);
return FormatDate(myDate, "mm/dd/yyyy");

do I need to add or delete something to make it work? I have a todays date rule called “Date Rule” that I replaced the “offerstartdate” 

any advice?

Link to comment
Share on other sites

1 hour ago, Mike_Marshfield said:

Not sure you will be able to see that email Alex

so my today’s date rule is this

return FormatDate (new Date (), “1m d, yyyy”);

so I need another rule for 1 year from todays date

In that case, you don't need that second rule to format the current date just to have the other rule call it.  You can just have a single rule like so:

var myDate = new Date();
myDate.setFullYear(myDate.getFullYear() + 1);
return FormatDate(myDate, "mm/dd/yyyy");

or:

var myDate = Today();
myDate.setFullYear(myDate.getFullYear() + 1);
return FormatDate(myDate, "mm/dd/yyyy");
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...