Expand my Community achievements bar.

SOLVED

Date field to populate day

Avatar

Level 1

Hi

I am using Adobe LiveCycle Designer ES4 and I would like to use the existing date field and when the user chooses the date an additional field would populate the day of the week. Is this possible without too much script being used.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

this isn't very complicated.

Here's a sample for you: Dateien freigegeben - Acrobat.com

You just need 7 fields named "Day" and a small script in the exit event of your date field.


if (not $.isNull) then


  var datePattern = "DD.MM.YYYY"


  var date = Date2Num($.formattedValue, datePattern)


  for i = 0 upto 6 do


  Day[i] = Upper(Num2Date(Sum(date, i), "EEEE"))


  endfor


else


  for i = 0 upto 6 do


  Day[i] = ""


  endfor


endif


View solution in original post

5 Replies

Avatar

Level 10

Hi,

that's very easy to do.

You need a small FormCalc script.in the calculate event of the field, that will display the day of week.

If you date fiels is named DateField1 and displays dates in the format MM/DD/YYYY use:


$ = Num2Date(Date2Num(DateField1.formattedValue, "MM/DD/YYYY"), "EEEE")


It will return Wednesday for todays date.

if you just want the number of the day use "E" instead of "EEEE" as pattern.

Avatar

Level 3

Hi Radzmar,

I always enjoy and learn from your posts!

I have a slight twist to the day of week issue that you resolved above. 

I have a date field called "First_Day", and seven text fields, one for each day of the week.  I can get the above to work on the first text field, but what I want to do is change the date that is evaluated to First_Day + 1, First_Day + 2, etc.

My goal is to enter or pick a date in the date field "First_Day".  Then, use that date to extract the day of week for each of the seven text fields, labeled "Day_1", Day_2", etc., incrementing the date as you go along.

So if...

First_Day = 08/25/15

Then, the text field values should be..

Day_1 = Tuesday

Day_2 = Wednesday

Day_3 = Thursday

Day_4 = Friday

Day_5 = Saturday

Day_6 = Sunday

Day_7 = Monday

As an added bonus, I would like to convert the days of the week to uppercase.

Thanks for your time!

Avatar

Correct answer by
Level 10

Hi,

this isn't very complicated.

Here's a sample for you: Dateien freigegeben - Acrobat.com

You just need 7 fields named "Day" and a small script in the exit event of your date field.


if (not $.isNull) then


  var datePattern = "DD.MM.YYYY"


  var date = Date2Num($.formattedValue, datePattern)


  for i = 0 upto 6 do


  Day[i] = Upper(Num2Date(Sum(date, i), "EEEE"))


  endfor


else


  for i = 0 upto 6 do


  Day[i] = ""


  endfor


endif


Avatar

Level 3

Radzmar,

Thanks for the reply.  I tried your suggestion, but it doesn't work quite right.  I selected 8/20/15 as the date in the First_Day field, which is a Thursday.  In the screen shot below, you can see that the script started with Monday, and it started with the second field, instead of the first.  What do you think?

Here's a link to the form:  https://www.dropbox.com/s/6tvb11ch0q9lnha/expense%20report%20v1_1%20-%20lc%20original.pdf?dl=0

01Day.jpg

Thanks again for your help!

Avatar

Level 3

Radzmar,

I got it working.  My fault.  I did not adjust the date format to match the display format of the First_Day date field.

Thanks again!