cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to Covert date in the JSON data

arvindnsn
Contributor

Hello,

I am trying to work with the date (timestamp to be precise) and getting into trouble. My requirement is below.

I have a stage table where the data is stored as JSON in a Variant Column and the data looks like below in that column.

{
โ€œmessage_bodyโ€: {
โ€œcampus_codeโ€: โ€œTESTโ€,
โ€œcampus_nameโ€: โ€œTESTโ€,
โ€œevent_typeโ€: โ€œTESTโ€,
โ€œlocation_codeโ€: โ€œA00000โ€,
โ€œlocation_nameโ€: โ€œTESTโ€,
โ€œorderโ€: {
โ€œcredit_totalโ€: 0,
โ€œapp_versionโ€: โ€œ1.0.9โ€,
โ€œasapโ€: 1,
โ€œorder_datetimeโ€: โ€œ2021-01-08 18:19:34โ€
}
โ€œtimezone_offset_minutesโ€: -360,
}
}
I have below requirements.

  1. Convert the Datetime into only date, so i tried the below and its failing

select TO_TIMESTAMP((body:message_body:order:order_datetime), โ€˜yyyy-mm-dd HH24:MI:SSโ€™) FROM โ€œstage_tableโ€. its failing with below error message

SQL compilation error: error line 1 at position 7 too many arguments for function [TO_TIMESTAMP(GET(GET(GET(stage_table.BODY, โ€˜message_bodyโ€™), โ€˜orderโ€™), โ€˜order_datetimeโ€™), โ€˜yyyy-mm-dd HH24:MI:SSโ€™)] expected 1, got 2

  1. I have to subtract the minutes from order_datetime. I have to subtract timezone_offset_minutes from
    order_datetime

select datetime, dateadd(minute, -300, body:message_body:order:complete_datetime) FROM
โ€œstage_tableโ€. its failing with below error message

Timestamp โ€˜โ€™ is not recognized

Any quick help is hugely appreciated.

Thanks
Aravind N

1 REPLY 1

ptaylor
Employee
Employee

I suggest not trying to do this in SQL. Just get the datetime as a string, and use a Mapper expression to do the date manipulation using the SnapLogic expression language.