Expand my Community achievements bar.

SOLVED

Date addition

Avatar

Level 3

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!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

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,

View solution in original post

3 Replies

Avatar

Correct answer by
Former Community Member

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,

Avatar

Level 3

Thanks, I'll give it a go and let you know.

Avatar

Level 3

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

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----