Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Problem with Date calc

Avatar

Level 1

I'm trying to get this FormCalc calculation to work:

Date2Num (form1.Page1_SF.EffectDates.endDate, "M/D/YYYY") - Date2Num (form1.Page1_SF.EffectDates.startDate, "M/D/YYYY")

Evently, I will divide it by 7 to get the number of weeks, but the initial calculation does not want to work after entering in the dates.

Can you tell me what is wrong with my forumula?

Thank you.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Odd. Something strange about the Date2Num format. I changed them in the calculation to "YYYY-MM-DD" and it works. Note it is calculating the number of elapsed days.

if (HasValue(form1.Page1_SF.EffectDates.endDate) & HasValue(form1.Page1_SF.EffectDates.startDate)) then
$.rawValue = Date2Num(form1.Page1_SF.EffectDates.endDate.rawValue,"YYYY-MM-DD") -Date2Num(form1.Page1_SF.EffectDates.startDate.rawValue,"YYYY-MM-DD")
else
  $.rawValue = null
endif
Steve

View solution in original post

4 Replies

Avatar

Former Community Member

Do the date patterns on each date field match the date patterns on your calculation?

Steve

Avatar

Level 1

Yes, here is the date pattern:

date{M/D/YYYY}

I'm looking at your PDF now.

Avatar

Former Community Member

If you can forward the form to stwalker.adobe@gmail.com I would be happy to take a look.

Steve

Avatar

Correct answer by
Former Community Member

Odd. Something strange about the Date2Num format. I changed them in the calculation to "YYYY-MM-DD" and it works. Note it is calculating the number of elapsed days.

if (HasValue(form1.Page1_SF.EffectDates.endDate) & HasValue(form1.Page1_SF.EffectDates.startDate)) then
$.rawValue = Date2Num(form1.Page1_SF.EffectDates.endDate.rawValue,"YYYY-MM-DD") -Date2Num(form1.Page1_SF.EffectDates.startDate.rawValue,"YYYY-MM-DD")
else
  $.rawValue = null
endif
Steve
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] ----