Skip to main content
Inspiring
Dec 1, 2021 4:19 PM UTC
Solved

Convert text data to text formatted data

Hello 

how to convert this text string: "2022-11-12 00:00:00"(Text)

to text string in format "dd/MM/yyyy" ?

Thank you!. 

    tajinders0001
    Inspiring
    Dec 2, 2021 4:05 AM UTC

    Hi Vladimir,

    Please use the following code to convert the given text string to date time format

    a!localVariables(
    local!myDate:"2022-11-12 00:00:00",
    local!splitDate:fn!split(local!myDate,"-"),
    local!splitDay:fn!split(local!splitDate[3]," "),
    local!splitTime:fn!split(local!splitDay[2],":"),
    local!dateTime:fn!datetime(
    local!splitDate[1],local!splitDate[2],local!splitDay[1],
    local!splitTime[1],local!splitTime[2],local!splitTime[3]
    ),
    fn!todate(local!dateTime)
    )

    After that you can either use todate() or text() function for display purposes.

    3 replies

    danny.verb
    Employee
    Dec 1, 2021 4:59 PM UTC

    You can use the text function! In your case, it's best to first convert your string to a date or datetime type. Then do

    text(local!myDate, "dd/MM/yyyy")

    New Participant
    Dec 2, 2021 4:02 AM UTC

    Text function is perfectly consistent. Thank you for the answer! lolbeans

    tajinders0001
    Inspiring
    Dec 2, 2021 4:05 AM UTC

    Hi Vladimir,

    Please use the following code to convert the given text string to date time format

    a!localVariables(
    local!myDate:"2022-11-12 00:00:00",
    local!splitDate:fn!split(local!myDate,"-"),
    local!splitDay:fn!split(local!splitDate[3]," "),
    local!splitTime:fn!split(local!splitDay[2],":"),
    local!dateTime:fn!datetime(
    local!splitDate[1],local!splitDate[2],local!splitDay[1],
    local!splitTime[1],local!splitTime[2],local!splitTime[3]
    ),
    fn!todate(local!dateTime)
    )

    After that you can either use todate() or text() function for display purposes.