Convert Text to DateandTime

Hi Team,

I have below text and I want to convert it into a Date and Time.

Example:

Text:  "01/07/2025 12:00:35 PM"

Date and Time: 01/07/2025 12:00:35 PM or 01/07/2025 12:00:35 PM GMT+00:00

  Discussion posts and replies are publicly visible

Parents Reply Children
  • a!localVariables(
      local!reportdata: {{c3: fn!datetime(2025, 1, 7, 5, 12, 2, 300), c0: "Workflow_00001_01/07/2025 12:00:35 PM", c1: 1, c2: "Process", dp1: null, dp0: 1055133, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 3, 5, 20, 6, 410), c0: "Workflow_0001_01/03/2025 06:09:35 AM", c1: 1, c2: "Process", dp1: null, dp0: 1060892, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 2, 12, 40, 13, 960), c0: "Workflow_0001_12/07/2022 06:09:35 AM", c1: 0, c2: "Process", dp1: null, dp0: 1060315, dp3: null, dp2: null}},
      a!forEach(
        items: local!reportdata,
        expression: if(a!isNotNullOrEmpty(fv!item), {
          taskName: fv!item.c2,
          Id: if(
            a!isNotNullOrEmpty(fv!item.c0),
            if(
              left(fv!item.c0, 3) = "PN",
              index(split(fv!item.c0, "_"), 3, null),
              index(split(fv!item.c0, "_"), 2, null)
            ),
            null
          ),
          SubDateTime: index(split(fv!item.c0, "_"), 3, null)
        }, null)
      )
    )

  • Certified Senior Developer
    in reply to Sameer Ul Haq

    Add the todatetime() function in line 16 it is working for me not returning any error.. 

    a!localVariables(
      local!reportdata: local!reportdata: {{c3: fn!datetime(2025, 1, 7, 5, 12, 2, 300), c0: "Workflow_00001_01-07-2025 12:00:35 PM", c1: 1, c2: "Process", dp1: null, dp0: 1055133, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 3, 5, 20, 6, 410), c0: "Workflow_0001_01-03-2025 06:09:35 AM", c1: 1, c2: "Process", dp1: null, dp0: 1060892, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 2, 12, 40, 13, 960), c0: "Workflow_0001_12-07-2022 06:09:35 AM", c1: 0, c2: "Process", dp1: null, dp0: 1060315, dp3: null, dp2: null}},
      a!forEach(
        items: local!reportdata,
        expression: if(a!isNotNullOrEmpty(fv!item), {
          taskName: fv!item.c2,
          Id: if(
            a!isNotNullOrEmpty(fv!item.c0),
            if(
              left(fv!item.c0, 3) = "PN",
              index(split(fv!item.c0, "_"), 3, null),
              index(split(fv!item.c0, "_"), 2, null)
            ),
            null
          ),
          SubDateTime: a!localVariables(
            local!date:split(fv!item.c0,"_"),
            todatetime(substitute(index(local!date,3,null),"-","/"))
          )
        }, null)
      )
    )

  • Certified Senior Developer
    in reply to Sameer Ul Haq

    If possible can you post the screenshot with the error

  • Its not working if reportdata is 

    local!reportdata: {{c3: fn!datetime(2025, 1, 7, 5, 12, 2, 300), c0: "Workflow_00001_01-07-2025 12:00:35 PM", c1: 1, c2: "Process", dp1: null, dp0: 1055133, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 3, 5, 20, 6, 410), c0: "Workflow_0001_01-03-2025 06:09:35 AM", c1: 1, c2: "Process", dp1: null, dp0: 1060892, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 2, 12, 40, 13, 960), c0: "Workflow_0001_12-07-2022 06:09:35 AM", c1: 0, c2: "Process", dp1: null, dp0: 1060315, dp3: null, dp2: null}}

  • Certified Lead Developer
    in reply to Sameer Ul Haq

    todatetime(substitute("12-07-2022 06:09:35 AM", "-", "/"))

  • Certified Lead Developer
    in reply to Sameer Ul Haq

    Where is this value in the c0 field coming from? Why is it like this? Is there no way to get that date directly as an individual field?

  • Certified Senior Developer
    in reply to Sameer Ul Haq

    Try  the below code

    a!localVariables(
      local!reportdata: local!reportdata: {{c3: fn!datetime(2025, 1, 7, 5, 12, 2, 300), c0: "Workflow_00001_01-07-2025 12:00:35 PM", c1: 1, c2: "Process", dp1: null, dp0: 1055133, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 3, 5, 20, 6, 410), c0: "Workflow_0001_01-03-2025 06:09:35 AM", c1: 1, c2: "Process", dp1: null, dp0: 1060892, dp3: null, dp2: null}, {c3: fn!datetime(2025, 1, 2, 12, 40, 13, 960), c0: "Workflow_0001_12-07-2022 06:09:35 AM", c1: 0, c2: "Process", dp1: null, dp0: 1060315, dp3: null, dp2: null}},
      a!forEach(
        items: local!reportdata,
        expression: if(a!isNotNullOrEmpty(fv!item), {
          taskName: fv!item.c2,
          Id: if(
            a!isNotNullOrEmpty(fv!item.c0),
            if(
              left(fv!item.c0, 3) = "PN",
              index(split(fv!item.c0, "_"), 3, null),
              index(split(fv!item.c0, "_"), 2, null)
            ),
            null
          ),
          SubDateTime: a!localVariables(
            local!date:split(fv!item.c0,"_"),
            todatetime(substitute(index(local!date,3,null),"-","/"))
          )
        }, null)
      )
    )

  • its eliminating the seconds part from time and date time is not in a format mm/dd/yyyy hh:mm:ss AM/PM