7 Replies Latest reply on Nov 14, 2008 2:26 PM by (Garrett_Shelton)

    Date formatted as Day of the Week

      I'm using LiveCycle Designer 8.0 and I'm trying to retrieve a date from a Date/Time field and reformat it to the corresponding day of the week in another field next to the Date/Time Field.

      I know the format would be EEEE to get the day of the week, I just don't think I'm doing something correctly. When I set the Binding Data Pattern to EEEE, it tells me that it's an incorrect Data Pattern. Can I put this in as a FormCalc script or is there something I'm missing?

      TIA,

      Garrett
        • 1. Re: Date formatted as Day of the Week
          gkaiseril MVP & Adobe Community Professional
          If you look at the calculation script associated with the "Current Date" field, you will see that a standard short date format is applied:

          // Current Date in short-style date format.
          $.rawValue = num2date(date(), DateFmt(1))

          So, I would expect you will need to use a custom calculation script using the required format string of "EEEE" or "EEE".
          • 2. Re: Date formatted as Day of the Week
            Level 1
            I'm not understanding how to create a "custom script". Every time I try to use codes dealing with formatting the date, they have to be in a specific orientation and usually don't include the option to use the format string "EEEE". Is it possible to use the DateFmt(4) code and omit the D,M,Y? I'm trying not to get anyone to write my code for me, but it's becoming more and more difficult.

            Thanks for all your help so far Geo.
            • 3. Re: Date formatted as Day of the Week
              Patrick Leckey Level 3
              util.printd({cFormat: "dddd", oDate: new Date()});

              The above will return simply "Monday", "Tuesday", "Wednesday", etc. Whatever the current day of the week is.

              This is JavaScript, not FormCalc, so make sure you set the dropdown where you place this code accordingly.
              • 4. Re: Date formatted as Day of the Week
                gkaiseril MVP & Adobe Community Professional
                For the current date you careate a datetime field with a data format of "date" and then use the following FormCalc calculation script:

                // Current Date showing day of week.
                $.rawValue = num2date(date(), "EEEE")
                • 5. Re: Date formatted as Day of the Week
                  Level 1
                  These both work great, but I'm not necessarily going to be using the current date. A date is put into the Date field "OccurenceDate" and then this code should calculate the day of the week in the field "OccurenceDay". I had gotten it to work with OccurenceDay being a Text Field and using the Format function below, but it wouldn't show if all I was formatting was the day.

                  var d = OccurenceDate.rawValue
                  Format("EEEE M", d)

                  OccurenceDate: 2008-11-11
                  OccurenceDay: Tuesday 11

                  If I leave the "M" out, it won't display the Tuesday.

                  Does this make any better sense?

                  You're giving me great ideas and I really appreciate all your help. Thanks.
                  • 6. Re: Date formatted as Day of the Week
                    gkaiseril MVP & Adobe Community Professional
                    If you check the 'Scripting Reference' under LiveCycle Designer's 'Help' menu option, the 'Date()' funciton returns the number of days since Jan 1, 1900, LiveCycle Designer's Epoch date. You need to get your date string converted to the number of days from the Epoch date using the "Date2Num()" function. And the format of the data string is very important, if the input string does not match the format string the function does not work.

                    So if your 'OccurenceDate' has a "formattedValue" string of "YYYY-MM-D" you could use the following FormCalc calculation script in the field you want the day of week to be displayed in:

                    Num2Date( Date2Num(OccurenceDate.formattedValue, "YYYY-MM-DD"), "EEEE")
                    • 7. Re: Date formatted as Day of the Week
                      Level 1
                      That was the problem. My date format is "DD-MM-YYYY". That fixed it. I know it may have been frustrating, but thanks for all your help.