Skip to main content
April 26, 2024
Solved

Convert string to timestamp(6)

  • April 26, 2024
  • 7 replies
  • 0 views

Hello everyone,

I have a field for created date of type varchar(255) and it has the value in string, for example: "20220505101000345600", what I did before was converting it to date before saving it to database with this expression: 

concat(
mid(
index(
ri!pulsarMessageValue,
"CREATION_TIMESTAMP",
null
),
5,
2
),
"/",
mid(
index(
ri!pulsarMessageValue,
"CREATION_TIMESTAMP",
null
),
7,
2
),
"/",
left(
index(
ri!pulsarMessageValue,
"CREATION_TIMESTAMP",
null
),
4
)
),

but now I am required to do store it as timestamp so then I can show it in the interface. My question is if is there any way to store it as datetime and then in the interface part I can use the formatted column or I need to convert it in the interface like this:

    Best answer by blerinad9411

    Yes, that's what I did as well but instead of tostring I used the datetext function. Thanks

    a!localVariables(
      local!pulsarMessageValue: "20220505101000345600",
      local!dateTime: datetime(
        left(local!pulsarMessageValue, 4),
        mid(local!pulsarMessageValue, 5, 2),
        mid(local!pulsarMessageValue, 7, 2),
        mid(local!pulsarMessageValue, 9, 2),
        mid(local!pulsarMessageValue, 11, 2),
        left(mid(local!pulsarMessageValue, 13, 8), 2)
      ),
      datetext(
        local!dateTime,
        "HH:mm:ss, dd.MM.yyyy"
      )
    )

    7 replies

    davidj137213
    Brainy
    April 26, 2024

    Why don't you use it as a string instead of converting to date??

    April 26, 2024

    I got a feedback that is better to store it as timestamp rather than string and then do the calc in the interface part, that's why

    davidj137213
    Brainy
    April 26, 2024

    If you only need it in the interface, and don't need it for calculations..... use string...

    shubhama926776
    Brainy
    April 26, 2024

    Hello [mention:0d77b95d889c420097b2afce6f897f56:e9ed411860ed4f2ba0265705b8793d05] ,

    Based on your input i tried converting text to dateTime verify and make changes according to your need.

    a!localVariables(
      local!pulsarMessageValue: "20220505101000345600",
      local!dateTime: datetime(
        int(left(local!pulsarMessageValue, 4)),
        int(mid(local!pulsarMessageValue, 5, 2)),
        int(mid(local!pulsarMessageValue, 7, 2)),
        int(mid(local!pulsarMessageValue, 9, 2)),
        int(mid(local!pulsarMessageValue, 11, 2)),
        int(
          left(mid(local!pulsarMessageValue, 13, 8), 2)
        )
      ),
      text(
        local!dateTime,
        "yyyy-MM-dd HH:mm:ss"
      )
    )

    Let me know if that works for you.

    शुभम्
    stefanhelzle0001
    Brainy
    April 26, 2024

    Are you aware that the tostring() function does not provide any means of formatting and no second parameter? You should try the text() function instead.