Expand my Community achievements bar.

Complete novice needing help with simple date/time functions

Avatar

Level 1

I will admit off the bat that I don't even know what javascript is.

I am making a fillable form for people that will most likely print it off, write on it, and hand it back to me, so I don't want to spend a lot of time on it, but I LOVE fillable forms, and have successfully distributed a couple of different ones.

Now I am tackling a 2 week timesheet, and I am all messed up over the dates.

I have a date field for Sunday, and after the supervisor chooses that date, it would be great if the other fields could auto-fill across, but I cannot figure out how to do that, even using help.

And this might sound really stupid, but I cannot get a date/time field to act as a time field. It only wants to do dates. I tried entering the pattern as time {HH:mm} and every other variation that I saw in the Help feature, but it keeps saying that it's an invalid pattern.

I am making a date/time object, and in its display pattern, I am entering the type of format I want. Is this totally wrong?

Ideally, I want to have a simple box where you enter the start time as 7:00 a.m, then the end time as 3:00 p.m, the next box as length of lunchbreak, like 1:00 or 0:30, and have it automatically calculate the number of hours worked per day less the break.

Is even something I should attempt to try? I am trying to muddle through on my own, I thought it would be relatively easy, like excel would be, but I am lost.

Any help would be gratefully appreciated!

5 Replies

Avatar

Former Community Member

The attached 'GetDaysStartingSunday.pdf' produces the following results:

p1.png

You pick Sunday's date and the dates for rest of the week are calculated. You can see the FormCalc functions handle dates across months. The form has no logic to validate that the date picked for Sunday is actually a Sunday. This is possible, however. The exit event on the field 'sun', below, converts the selected date to a number (Date2Num) representing the number of days since 01/01/1900. Each subsequent calculation adds 1 to that number and converts the number to a date (Num2Date).

// form1.page1.subform1.table.row.sun::exit - (FormCalc, client)

var dayNum = Date2Num($.formattedValue,"MM/DD/YYYY")

mon.rawValue = Num2Date(dayNum+1,"MM/DD/YYYY")

tues.rawValue = Num2Date(dayNum+2,"MM/DD/YYYY")

wed.rawValue = Num2Date(dayNum+3,"MM/DD/YYYY")

thurs.rawValue = Num2Date(dayNum+4,"MM/DD/YYYY")

fri.rawValue = Num2Date(dayNum+5,"MM/DD/YYYY")

sat.rawValue = Num2Date(dayNum+6,"MM/DD/YYYY")

I have attached another time sheet example that allows users to enter time in/out and calculates the daily hours and a total. The time must be entered in 24-hour format (where 8:00 AM is 0800 and 5:00 PM is 1700, for example). It might give you some ideas.

Steve

Avatar

Level 4

I tried your suggestion and when I pick a date it appears in the appropriate field, but when I click in the next field it fills things in, but with the wrong date, starting in 1900.  My scripting matches what you did in the example file.  I'm trying to populate down a column rather than across the row.  Do I need to do something a little different?

Avatar

Former Community Member

Columns will work a little different.

I added a second table with a row called 'row_' and column called 'date'. In the exit event of 'row[0].date' I added the script, depicted below, that will calculate the dates for the next 6 days.

p.png

Steve

Avatar

Level 4

Steve,

What you're saying more or less makes sense to me.  I'm trying to follow your example, but it's still not working out correctly.  I was going to attach the file your you to look at but I'm able to find the place to attach files on here any more.  I thought it was at the bottom of the screen.  So if it would be helpful to see the file, let me know how I can get it to you.  Also, how do I get the date to appear MM/DD/YYYY when it is selected rather than with text (Mar 9, 2010)?  Thanks!

Avatar

Former Community Member

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