Expand my Community achievements bar.

SOLVED

Date Calculations

Avatar

Former Community Member

I am trying to calculate dates for a two-week timesheet.  The person doing the timesheet enters the pay period ending date.  When they click on to the next box, where they enter their name, etc., I want to automatically fill in the dates next to each day in the table for the next 14 days.  I decided to subtract one from the pay period ending date, insert that in the area next to Friday (6th day, 2nd week), and so on until I got to the first day in the pay period, which would equal the (pay period ending date - 13).  Pretty simple to explain, but I have no idea how the code should look, and if I calculate, or click, or what.

I have seen the Num2Date and Date2Num functions, but I don't know where I should be doing these calcs and how to define the field that is the answer so I can then display this in the table.  I have tried to create calculations that reference a field I have defined as read only for each date.  Except I get errors that say Wk2Fri is no good.  Do I have to define that field somewhere in the code, and if I do, where and how?

Is there a book that explains some of this stuff out there.  I get tired of asking and looking like an idiot.

If anyone wants to see the form, leave an email address and I'll send it to you.  The attach files routine is not working (at least it wasn't the last time I tried it.)  I'll try to aattach it now.  Let me know if you can't see it.

Thanks for your help.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Here is my cut at your form. It is not quite complete. It takes the date from the date picker and uses the FormCalc date2num and num2date functions to populate the table with the dates for the two week period preceeding the end date.

The attached .png highlights the result of picking an end date that is not a Saturday.

Steve

View solution in original post

9 Replies

Avatar

Former Community Member

There is no such thing as a bad question.

Forward the form to stwalker.adobe@gmail.com and I will take a look.

Steve

Avatar

Correct answer by
Former Community Member

Here is my cut at your form. It is not quite complete. It takes the date from the date picker and uses the FormCalc date2num and num2date functions to populate the table with the dates for the two week period preceeding the end date.

The attached .png highlights the result of picking an end date that is not a Saturday.

Steve

Avatar

Former Community Member

Steve -

Not sure what is happening, but sometimes when I test the form, the date gets filled in after entering the first date, and sometimes it doesn't.  I can tell you that after entering the two weeks ending date, the date field in the first column gets filled in with that date, but the other dates and the days do not automatically populate.  I thought I had a problem, but then it started working.  Not it isn;t.  I tried it in both Designer, Acrobat Pro and Acrobat.  When ti works, it works in all three.  When it doesn't, it doesn't in all three.  ANy good ideas?

Thanks for your help.  I appreciate it very much.

DF

BTW I have attached my latest version.

Avatar

Former Community Member

Looks like when I enter a two week end date that includes today's date, it doesn't work.  If I move it our a week use that as an end date, the dates populate.  Try it.  Use May 9 as the end date and see what happens.  The use May 16.  It works.  Go figure.  Any ideas?  Thanks.

Avatar

Level 10

Hi,

I think that the.... ".formattedValue,"MMMM DD, YYYY")" in the script should only have one "D" to match the date pattern in the cell/object pattern tab.

Hope this helps,

N.

Avatar

Former Community Member

Niall is absolutely correct. I made the mistake of incorrectly formatting the two week ending date in the calculation for the previous 14 days.

I had

var dateNum = date2num(form1.page1.header.twoWeeksEnding.formattedValue,"MMMM DD, YYYY")
$ = num2date(dateNum,"MM/DD")

It should be

var dateNum = date2num(form1.page1.header.twoWeeksEnding.formattedValue,"MMMM D, YYYY")
$ = num2date(dateNum,"MM/DD")

The corrected version is attached.

Steve

Avatar

Former Community Member

Thanks, Niall, and thanks, Steve.  I appreciate all the help on this.

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