How to use the DateDiff variable in Process Flow?

 20 Replies
 2 Subscribed to this topic
 52 Subscribed to this forum
Sort:
Author
Messages
ryand
Veteran Member
Posts: 51
Veteran Member

    Can you use the DateDiff function to compare two dates in YYYYMMDD or MM/DD/YYYY format?  When I compare the dates in JS format it gives me an error "TypeError: Cannot find function getTime.

    John Henley
    Posts: 3353
      You need to pass in a date variable not a string (you can convert to date format using pfDate() function, e.g.:
      DateDiff(pfDate(datestring1,'yyyy/mm/dd'),pfDate(datestring2,'yyyy/mm/dd'))
      Thanks for using the LawsonGuru.com forums!
      John
      ryand
      Veteran Member
      Posts: 51
      Veteran Member

        I'm getting a result like this: 1.0810584E12? 

        John Henley
        Posts: 3353
          Well, what dates are you using?
          ________________________________
          From: forums-bpm-pflow@lawsonguru.com [forums-bpm-pflow@lawsonguru.com]
          Sent: Wednesday, October 28, 2009 4:04 PM
          To: John Henley
          Subject: RE: How to use the DateDiff variable in Process Flow? [00006700:00009155]

          [https://images.lawsonguru.com/logos/LawsonGuru_com_200.jpg]<https://www.lawsonguru.com/>
          Lawson ProcessFlow Forum Notification
          A message was posted to a thread you are tracking.
          RE: How to use the DateDiff variable in Process Flow?
          Posted by: ryand
          10/28/2009 03:40 PM

          I'm getting a result like this: 1.0810584E12?


          ________________________________

          To view the complete thread and reply via your browser, please visit:
          https://www.lawsonguru.co...fc/9155/Default.aspx

          You were sent this email because you opted to receive email notifications when someone posted and/or responded to a message on this forum.
          To unsubscribe to this thread please visit your user profile page and change your subscription options.

          Thank you,
          LawsonGuru.com

          Thanks for using the LawsonGuru.com forums!
          John
          Sam Simpson
          Veteran Member
          Posts: 239
          Veteran Member
            John's example should work except put two (( in front. i.,e. DateDiff((.....
            ryand
            Veteran Member
            Posts: 51
            Veteran Member

              Nice, i finally got it to work using John's example.  Thanks for your help as always!

              Karen Sheridan
              Veteran Member
              Posts: 141
              Veteran Member
                I am trying to use DateDiff with 2 fields that should already be dates:

                DateDiff(PERSACTION_EFFECT_DATE, Today())

                I've tried various combinations, but haven't found one that works other than just hard coding the dates and using pfDate.

                TIA,
                Karen
                David Williams
                Veteran Member
                Posts: 1127
                Veteran Member
                  When you reference a variable from a Query or an AGS call the variable is usually in a String format. You would have to reassign it to a date variable in order for the DateDiff function to work.
                  David Williams
                  Karen Sheridan
                  Veteran Member
                  Posts: 141
                  Veteran Member
                    Do you know if Today() needs conversion? It gives me an error if I try to pfDate convert it.

                    Here is my code that isn't working:
                    DateDiff(pfDate(PERSACTION_EFFECT_DATE,'YYYYMMDD'),today()) > 3
                    David Williams
                    Veteran Member
                    Posts: 1127
                    Veteran Member
                      You would be better off creating two variables with the dates you want to compare and then use those variables in your DateDiff function.
                      David Williams
                      Karen Sheridan
                      Veteran Member
                      Posts: 141
                      Veteran Member
                        This now working, but....
                        I added a variable strRunDate = DateString(today(),'yyyymmdd')

                        Then the condition code is
                        DateDiff(pfDate(PERSACTION_EFFECT_DATE,'mm/dd/yyyy'),pfDate(strRunDate,'yyyymmdd')) > 3

                        the 2 dates are 10 days apart - its evaluating correctly and sending the email, but I am getting this error

                        Flow ended with error code (1) - Activity error
                        Information code: 0
                        Return message: All Branch Conditions false
                        Error occurred in activity: Branch6250
                        David Williams
                        Veteran Member
                        Posts: 1127
                        Veteran Member
                          Well, that's a Branch error and if you're saying the email is working, it must be a Branch later in the flow?
                          David Williams
                          Karen Sheridan
                          Veteran Member
                          Posts: 141
                          Veteran Member
                            Branch6250 is the branch that triggers the email or ends the flow.
                            David Williams
                            Veteran Member
                            Posts: 1127
                            Veteran Member
                              That error in a Branch usually means that none of the conditions you set up were met and so it throws an error. Are you sure your DateDiff statement is working? Have you tried it where the email shouldn't be sent?

                              So you have two branch conditions in your Branch node? The first would be your DateDiff statement and the 2nd should be just the word true. The last condition in any Branch node should always be true so that the system knows that if none of the preceding conditions were met then the last one should always be followed.
                              David Williams
                              Wanda Schaaf
                              Basic Member
                              Posts: 12
                              Basic Member
                                Hello, I am struggling to get the DATEDIFF function to work in a branch situation. I am just trying to get a basic hardcoded statement to evaluate successfully.
                                This is the message I am getting in the Console screen when I run it remotely from Infor Process Designer.

                                Is there something I am doing wrong in the statement below?
                                Activity Branch650: Error evaluating expression: DATEDIFF(DAY,pfDate('20150701','yyyymmdd'),pfDate('2015/05/01','YYYY/MM/DD')) > 1

                                Thanks for any feedback!
                                Wanda
                                David Williams
                                Veteran Member
                                Posts: 1127
                                Veteran Member
                                  The Branch isn't really a good place to build complicated conditions. I would recommend you create a boolen variable (true or false) and use a JavaScript expression (Assign) to do your function and then update the boolen variable with the results (true or false) and use that variable in the Branch.
                                  David Williams
                                  Wanda Schaaf
                                  Basic Member
                                  Posts: 12
                                  Basic Member
                                    Thanks, I will give that a shot.
                                    Wanda
                                    Woozy
                                    Veteran Member
                                    Posts: 709
                                    Veteran Member
                                      Hi Wanda - The issue is that you have "DAY" as a parameter, but the Pflow DATEDIFF function only takes two dates as parameters, and then returns the number of days between those dates (absolute value).

                                      So, try this instead: DATEDIFF(pfDate('20150701','yyyymmdd'),pfDate('2015/05/01','YYYY/MM/DD')) > 1

                                      David is correct that it is better to do the boolean check outside of the branch, it should work within it as well in this case. I often do this to avoid creating bunches of variables that are really "throw aways".
                                      Kelly Meade
                                      J. R. Simplot Company
                                      Boise, ID
                                      Wanda Schaaf
                                      Basic Member
                                      Posts: 12
                                      Basic Member
                                        I tried Woozy's and David's suggestions and am still getting errors:

                                        Activity Assign6030: Error evaluating expression: BoolDayDiff = DATEDIFF(DAY,pfDate('20150701','yyyymmdd'),pfDate('2015/05/01','YYYY/MM/DD')) > 1;
                                        Variables in Process:
                                        BoolDayDiff = null

                                        Activity Assign6030: Error evaluating expression: BoolDayDiff = DATEDIFF(pfDate('20150701','yyyymmdd'),pfDate('2015/05/01','YYYY/MM/DD')) > 1;
                                        Variables in Process:
                                        BoolDayDiff = null

                                        Branch Branch650: Executing this branch node...
                                        Activity Branch650: Error evaluating expression: DATEDIFF(pfDate('20150701','yyyymmdd'),pfDate('2015/05/01','YYYY/MM/DD')) > 1
                                        Branch Branch650: evaluating branch rule DATEDIFF(pfDate('20150701','yyyymmdd'),pfDate('2015/05/01','YYYY/MM/DD')) > 1 to node AssisnStart
                                        Branch Branch650: evaluating branch rule 1 ==1 to node End-SQLEmpD

                                        Thanks for any extra help.
                                        Woozy
                                        Veteran Member
                                        Posts: 709
                                        Veteran Member
                                          Hi Wanda,

                                          Two things - js is case sensitive, so it needs to be "DateDiff" rather than "DATEDIFF". Also, your second date parameter format won't work. The only two format options are "yyyymmdd" and "mm/dd/yyyy" (also lower case).

                                          This is what worked for me: DateDiff(pfDate('20150701','yyyymmdd'),pfDate('20150501','yyyymmdd')) > 1
                                          Kelly Meade
                                          J. R. Simplot Company
                                          Boise, ID
                                          Wanda Schaaf
                                          Basic Member
                                          Posts: 12
                                          Basic Member
                                            Your statement above worked for me also. Thanks for all the great tips. I applied my variables to the statement also in the assign node and I have that working also.
                                            This is a great site and I am very greatful for the quick responses and help from everyone.

                                            Thanks again.
                                            Wanda Schaaf