AngelBenitez Posted June 6, 2023 Share Posted June 6, 2023 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. Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted June 7, 2023 Share Posted June 7, 2023 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. 1 Quote Link to comment Share on other sites More sharing options...
AngelBenitez Posted June 7, 2023 Author Share Posted June 7, 2023 @ThomasLewisThank you so much for this; I really appreciate it. However, how would I get the date for the upcoming week? For example, placing an order today (June 7th) would show June 14th. Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted June 7, 2023 Share Posted June 7, 2023 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. Quote Link to comment Share on other sites More sharing options...
AngelBenitez Posted June 7, 2023 Author Share Posted June 7, 2023 @ThomasLewis I put 0 for the weeks out, and it automatically jumped to July 12th. Do you know why this is the case Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted June 7, 2023 Share Posted June 7, 2023 As I explained, that's what the allow_same_day variable is for. If you want to allow it, then set it to true. Quote Link to comment Share on other sites More sharing options...
ThomasLewis Posted June 7, 2023 Share Posted June 7, 2023 I just realized that it's possible your month and day are being reversed by the DateFromString() function. Can you post a sample of how the date appears in your data file? Quote Link to comment Share on other sites More sharing options...
AngelBenitez Posted June 7, 2023 Author Share Posted June 7, 2023 @ThomasLewisIt worked! Thank you for taking the time to help me out! Quote Link to comment Share on other sites More sharing options...
AngelBenitez Posted June 7, 2023 Author Share Posted June 7, 2023 @ThomasLewis It's working fine. I accidentally put the incorrect date in Excel for the variable. Thank you once again! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.