Legacy Dev Forum Posts

 View Only

Sign Up

Convert String Text into Date

  • 1.  Convert String Text into Date

    Posted 06-05-2025 18:36

    Jaime_Perez | 2022-09-12 20:14:53 UTC | #1

    Hello,

    We are using bots to collect the day of the week using quick replies without using the builtin:date slot type. Here are the quick replies we have listed.

    • Today
    • Monday
    • Tuesday
    • Wednesday
    • Thursday
    • Friday

    We would like to grab the quick reply and convert it into a date format. For example, "Today" would equal "today's date (9/12/2022). Same for the rest, when they select a day of the week, it will return the next day of the week in a date format.

    Is there a way that we can customize the above? If so, any suggestions on how we can create a formula or expression that would support this?

    Thank you.


    tim.smith | 2022-09-19 17:14:17 UTC | #2

    What specific bot integration are you using? There are quite a few offerings.


    Jaime_Perez | 2022-09-19 18:07:36 UTC | #3

    Hi Tim,

    We are using Genesys dialog engine bot flows.

    Thank you.


    Ullyot_Jim | 2022-09-29 16:59:19 UTC | #4

    Hi @Jaime_Perez ,

    Thanks for asking!

    Yes, you can do this. I used a digital bot flow but this should also work in a bot flow as well. The solution presented here will use Architect's DayOfWeek function. We'll use the implementation that uses a Date value. For a given Date, this function returns 1 if the day on the date is Sunday, 2 for Monday, 3 for Tuesday, etc. etc.

    To start off with, create a DayOfWeekType slot type. It will be a list data type with values "Today", "Monday", "Tuesday", "Wednesday", "Thursday" and "Friday" ( add "Saturday" / "Sunday" if you'd like to as well ).

    Next on your bot add a DayOfWeekOrToday slot:

    For my demonstration bot here I also added a DateToProcess slot of type date so the bot asks what the starting date is so you can test different dates to ensure the logic is working right.

    And then there's an Ask for Slot action that prompts for the Today date:

    Remember to check that you got a date from that Ask for Slot by seeing if Slot.DateToProcess is set to a value:

    Next you'll want to add an Ask for Slot action that prompts the participant to tell the bot which of the weekdays or "Today" to select:

    with quick replies on the person chatting with the bot should see "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Today" buttons. :)

    And finally, now we're going to get to the actual function side of things. Add an Update Data where we'll set a Flow.DayOfWeekToFindAsInt integer variable value:

    That expression looks like this:

    If(Slot.DayOfWeekOrToday == "Today", DayOfWeek(Slot.DateToProcess), If(Slot.DayOfWeekOrToday == "Monday", 2, If(Slot.DayOfWeekOrToday == "Tuesday", 3, If(Slot.DayOfWeekOrToday == "Wednesday", 4, If(Slot.DayOfWeekOrToday == "Thursday", 5, If(Slot.DayOfWeekOrToday == "Friday", 6, -1 ))))))

    You can see how we're starting to take what the user entered and putting it in terms of day of week functionality now. "Today" is saying "give me the day of week from the date is they entered at the start of the bot". I think you'd probably want a Flow.DateToProcess variable that's set to:

    ToDate(GetCurrentDateTimeUtc())

    but remember to offset the datetime from GetCurrentDateTimeUtc() as appropriate for your usage as that will be in UTC.

    Time to make sure the value in Flow.DayOfWeekToFindAsInt isn't -1 before we make "the calculation":

    And then finally if we've got a valid day of week we assign the calculated next day of week or today to Flow.NextDateFound:

    where that expression is:

    AddDays( AddDays( Slot.DateToProcess, 7 - DayOfWeek(AddDays(Slot.DateToProcess, 7 - Flow.DayOfWeekToFindAsInt)) ), If(Slot.DayOfWeekOrToday != "Today" and Flow.DayOfWeekToFindAsInt == DayOfWeek(Slot.DateToProcess), 7, 0) )

    And you should be good to go.

    I know there was a lot of setup in this response to get to the final expression where we've resolved out the day of week to find as an integer but figured it would be good to show using a custom list slot type with specific values and how they could then map over to integers that are then used to compute a desired next day of week along with special case handling for "Today".

    FWIW, it's not Architect but here's an article that discusses similar next day of week calculation logic in Excel which wouldn't have stuff like the "Today" handling but might be of interest:

    https://www.got-it.ai/solutions/excel-chat/excel-tutorial/date-and-time/get-next-day-of-week

    Hope this helps!

    Jim


    Jaime_Perez | 2022-09-21 13:50:39 UTC | #5

    Hi @Ullyot_Jim,

    This is great! Would it be too much to ask if you could share the export of the bot flows via email? I know I'm being lazy here :laughing: but since you already have them in a flow format it would be great if you could share. If so, please send to my email: Jaime.Perez@avonusa.com.

    If you share, I can update and customize to our needs. I appreciate the response!


    Ullyot_Jim | 2022-09-21 14:34:36 UTC | #6

    Hi @Jaime_Perez ,

    Completely get it. Having an example flow to tweak and twiddle makes things much easier. :+1:

    Does your organization have digital bot flows available or just bot flows? I used a digital bot flow for the demo flow above. If digital bot flows are not available, I would need to go ahead and move the logic over to a bot flow because the above example flow uses some digital bot flow specific stuff like the markdown text builder and would need to switch over to communication sequence builders in a bot flow. Ironically, these parts of the flow are in that setup'y side of things and not the actual next day of week calculation part of it but would still be nice to have and watch it run / test away with those changes in place.

    Thanks,

    Jim


    Jaime_Perez | 2022-09-21 14:41:57 UTC | #7

    Hi @Ullyot_Jim, we do have access to digital bot flows and that is what I'll be using to set it up. Thank you!


    Ullyot_Jim | 2022-09-21 16:15:06 UTC | #8

    @Jaime_Perez , coolio!

    I'll make a tweak or two to it and then send if off so you can try it out.

    Also, typical disclaimer'y stuff here in that the sample flow is demo code. I just threw it together as a proof of concept so it's all "as-is", take or leave what you want from it and what not.

    Thanks!

    Jim


    Jaime_Perez | 2022-09-21 16:26:52 UTC | #9

    I completely understand! I also very much appreciate the help here! :) Thanks!!


    Jaime_Perez | 2022-09-21 18:13:17 UTC | #10

    @Ullyot_Jim, if we don't need to ask for a date, how would we automatically have the flow recognize today's date when they select "Today"? I tried messing with the expression but it's not working correctly when I update them.


    Jaime_Perez | 2022-09-21 19:20:56 UTC | #11

    Here is the error that we are getting when we convert the expression to Flow.DateToProcess


    Ullyot_Jim | 2022-09-21 20:02:45 UTC | #12

    Hi @Jaime_Perez ,

    I just sent you the digital bot flow export that you can import and give a whirl here.

    The error that you're seeing above looks to come from the fact that Flow.DateToProcess variable is a String type and the DayOfWeek function expects either a DateTime or a Date value so the expression parser is saying "wait, I can't get the day of week from a String".

    My guess is it'll probably be easiest to create a new digital bot flow, import the date bot export that I sent in the email in to that new digital bot flow, publish it and try it out.

    Thanks!

    Jim


    Ullyot_Jim | 2022-09-21 20:07:55 UTC | #13

    Hi @Jaime_Perez ,

    If you're wondering how to get "today", Architect has a GetCurrentDateTimeUtc() function and you can do this:

    ToDate(GetCurrentDateTimeUtc())

    The one thing to remember is that current date time returned from that function call is UTC so if you need to offset it a couple of hours to make it more applicable for a location you can always use the AddHours function prior to making the ToDate call.

    For example:

    ToDate(AddHours(GetCurrentDateTimeUtc(), -5))

    Jim


    Jaime_Perez | 2022-09-21 20:27:50 UTC | #14

    Hi @Ullyot_Jim,

    We actually got it to work! The expression we used at first was wrong but we ended up figuring out the correct format for it to work. Examples below. We appreciate the help!


    Ullyot_Jim | 2022-09-21 21:05:55 UTC | #15

    Hey @Jaime_Perez ,

    Excellent - that gets a hot tater salad! ( yeah, that's an internal Architect team'ism we use when something goes well so it's a good thing. Lol! :) )

    Glad it's working :+1:

    Jim


    system | 2022-10-28 07:17:05 UTC | #17

    This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 16251