Jump to content

Get Upcoming Date


AngelBenitez

Recommended Posts

Hello,

I am trying to create a template that does the following:

  • Get the date for the upcoming Wednesday from the day that an order is placed
  • Get the date for the upcoming Wednesday six weeks from the day that an order is placed
  • Get the date for the upcoming Wednesday twelve weeks from today from the day that an order is placed
  • Get the date for the upcoming Wednesday eighteen weeks from today from the day that an order is placed

For example, if I were to place an order today (June 6th), it would show June 7th, then the upcoming Wednesday six weeks from today is July 19, and so on

If anyone can assist me with this, I would greatly appreciate it.

Link to comment
Share on other sites

Dan Korn
This post was recognized by Dan Korn!

"Great answer!"

ThomasLewis was awarded 100 points.

function set_date(date_string, day_of_week, week_multiplier, same_day)
{
    var d = DateFromString(date_string);
    var day = (day_of_week +7 -d.getDay()) % 7;
    if (!same_day && !day) day = 7;

    return d.setDate(d.getDate() + day + (7 * week_multiplier));
}

//settings
var weekday = 3; //sunday = 0, wednesday = 3
var weeks_out = 0; //change 0 to how many weeks out, ie 6, 12, 18
var allow_same_day = false; //if false, items ordered on same day will push to following week
var order_date = Field("Order Date");
var date_format = "lm d, yyyy";

return FormatDate(set_date(order_date, weekday, weeks_out, allow_same_day), date_format); 

Give this a shot.

  • Like 1
Link to comment
Share on other sites

Change the weeks_out variable to how many weeks forward you want the date. This gets a little tricky when the order placed is on a Wednesday, that's what the allow_same_day variable is for. Once you make the rule(s), you can use the Validate button to check the values and play around with what settings work for you.

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...