Genesys Cloud - Main

 View Only
Discussion Thread View
  • 1.  Calculate the difference between two dates in Architect

    Posted 11-11-2022 10:35
    Hi,

    I need the expression to calculate the difference between the "current_date" and another date returned by an external Web Service (with format: yyyy-mm-dd) in order to obtain the number of days as difference in Architect.

    Thank you in advance for you help.

    Regards.
    #Routing(ACD/IVR)
    #SystemAdministration


  • 2.  RE: Calculate the difference between two dates in Architect

    Posted 11-11-2022 10:52
    There are Diff functions in the expression editor for this:


    You will need to make sure your two times ($NOW) and your time are in DateTime format or use MakeDate for that.  Then use the DateDiff to get the difference in days.  Never tried large differences like months or years, but should still return the number of days.

    ------------------------------
    Robert Wakefield-Carl
    Avtex Solutions, LLC
    Contact Center Innovation Architect
    https://www.Avtex.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 3.  RE: Calculate the difference between two dates in Architect

    Posted 11-11-2022 11:01
    Hi Robert,

    Many thanks for your reply, however, I find only "DateTimeDiff" in Architect expressions, I cannot find "DateDiff".
    Does the "DateTimeDiff" expression return "days" or "hours" ?

    Thank you.

    ------------------------------
    Mostafa Oudderhem
    SABIO FRANCE SAS
    ------------------------------



  • 4.  RE: Calculate the difference between two dates in Architect

    Posted 11-11-2022 11:11
    That should be in there.  Could be the type of expression you have.  Check using Update Data with a string or duration.  DateTimeDiff will return a datetime duration, which in Genesys Cloud is usually milliseconds.

    ------------------------------
    Robert Wakefield-Carl
    Avtex Solutions, LLC
    Contact Center Innovation Architect
    https://www.Avtex.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 5.  RE: Calculate the difference between two dates in Architect

    Posted 11-11-2022 11:24
    Thank you Robert, but only "datetimediff" expression exist either in update data string or duration.
    I don't think it exist only "datediff", I didn't found it in docs also.

    So if "datetimediff" works, I need to convert the milliseconds to seconds > minutes > hours and then days.




    ------------------------------
    Mostafa Oudderhem
    SABIO FRANCE SAS
    ------------------------------



  • 6.  RE: Calculate the difference between two dates in Architect

    Posted 11-11-2022 11:55
    Very interesting.  I would open a ticket.   Yes, if you get back milliseconds, you cannot use MakeDateTime as it only takes between 0 and 59 seconds - so lots of translation/calculation or use a web service to convert:  

    Python Program to Convert Seconds to Hours and Minutes - AskPython
    Convert Seconds to Hours, Minutes, and Seconds (calculateme.com)

    Here is the function:
    DateDiff
    Function
    Returns the difference between two Date values as a Duration.
    Duration DateDiff( Date date1, Date date2 )
    Calculates the difference between two Date values.
    Return Value
    • Duration : Returns the difference between the date1 and date2 parameters as a Duration. If the Date in date1 is after the date2, a positive Duration is returned. If the Date in date1 is before the date2, a negative Duration is returned. If they're the same, a 0 second Duration is returned.
    • Date  date1 : A Date value.
      • NOT_SET is not allowed
    • Date  date2 : The Date value to subtract.
      • NOT_SET is not allowed
    Availability
    • Valid for use in Bot Flow and Digital Bot Flow types.
    Examples
    DateDiff(MakeDate(2009, 3, 22), MakeDate(2009, 3, 20))
    OUTPUT
    A duration of 2 days.
    DateDiff(MakeDate(2009, 3, 20), MakeDate(2009, 3, 22))
    OUTPUT
    A duration of -2 days.


    ------------------------------
    Robert Wakefield-Carl
    Avtex Solutions, LLC
    Contact Center Innovation Architect
    https://www.Avtex.com
    https://RobertWC.Blogspot.com
    ------------------------------



  • 7.  RE: Calculate the difference between two dates in Architect

    Posted 11-13-2022 16:19
    As per the function notes, the DateDiff function is "Valid for use in Bot Flow and Digital Bot Flow types." Not sure if you want to use a simple Bot to do the conversion for you.

    ------------------------------
    Muhammad Zubair Awan
    Spark NZ Trading
    ------------------------------



  • 8.  RE: Calculate the difference between two dates in Architect

    Posted 11-13-2022 22:59
    There is a slight sort coming.  I created an idea for this:  Add DateDiff to all Expressions | Genesys Cloud Ideas Portal (aha.io)

    Dumb that it would be only for bots!

    ------------------------------
    Robert Wakefield-Carl
    Avtex Solutions, LLC
    Contact Center Innovation Architect
    https://www.Avtex.com
    https://RobertWC.Blogspot.com
    ------------------------------



Need Help finding something?

Check out the Genesys Knowledge Network - your all-in-one access point for Genesys resources