I would like to display a date in the future based off of a date a user enters in a date field as well as a choice they make out of a drop list.
Drop List (dl1) allows the user to select choices “1 week, 2 weeks, 3 weeks, 4 weeks” etc up to “9 weeks”. They have a date field (date1) that they input a date. I would like to place in a calculated read only date field that adds date1 + the result of dl1 – call this calc1 (set as a date field).
All the date codes I have found in searches always use the Date() function to call the current date – this will not work for me as I need to compare against a date the user enters into the form, not the current systems date.
I have placed a CALCULATE code in the calc1 that looks like this:
switch (dl1.rawValue)
{
case “1”:
this.rawValue = date1.rawValue + 7;
break;
case “2”:
this.rawValue = date1.rawValue + 14;
break;
}
And it would go on for all possible values in dl1. But of course this just appends the number 7 or 14 at the end of the date (if the date1 field was set to August 2, 2011 then the result I get is 2011-08-027 or 2011-08-0214).
Do I need to parse out the year, month, day out of date1 and do some manipulating that way? Or is there a handy date function already that can read a date value and add days into it?
Thanks!
Solved! Go to Solution.
Views
Replies
Total Likes
I would use FormCalc for date operations rather than JS....
here is simple and similar example...
var
dSelected
var
wSelected
var
dResult
dSelected
= Date2Num(DateSelect.rawValue, "YYYY-MM-DD")
wSelected
= WeekSelect.rawValue
dResult
= dSelected + (7 * wSelected)
DateResult.rawValue
= Num2Date(dResult, "YYYY-MM-DD")
and for the Dropdown I chose Specify Item Values in Object>>>Binding tab and I chose 1 for 1 week, 2 for 2 weeks.....
try this and let us know....
Good Luck,
Views
Replies
Total Likes
I would use FormCalc for date operations rather than JS....
here is simple and similar example...
var
dSelected
var
wSelected
var
dResult
dSelected
= Date2Num(DateSelect.rawValue, "YYYY-MM-DD")
wSelected
= WeekSelect.rawValue
dResult
= dSelected + (7 * wSelected)
DateResult.rawValue
= Num2Date(dResult, "YYYY-MM-DD")
and for the Dropdown I chose Specify Item Values in Object>>>Binding tab and I chose 1 for 1 week, 2 for 2 weeks.....
try this and let us know....
Good Luck,
Views
Replies
Total Likes
Thanks, I'll give it a go and let you know.
Views
Replies
Total Likes
Varma -
Thanks, this code did work for me. I was able to place in a calculated date field that ran this code and placed a date based off the fields I indicated.
Jim
Views
Replies
Total Likes
Views
Likes
Replies