cancel
Showing results for 
Search instead for 
Did you mean: 

Convert Json format date to SAP readable format

ricky_shaw
Contributor
258

Hi,
I am executing methods/URI's in Odata(SEGW) and I am getting dates in Json format Unix/Epoch Format : “\/Date(1567981296000)\/”.
How do i convert this to an SAP readable format like MM/DD/YYYY?
I googled this but could not find a proper straight fwd answer. I am getting '0 'as the answers for some of the googled ABAP codes.

Pls suggest.

Sandra_Rossi
Active Contributor
0 Kudos
The transformation is done implicitly by Simple Transformation format(ticks) and others. https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenst_option_format....
ricky_shaw
Contributor
0 Kudos
@ Sandra, How can i use this link to code in my prog?
Sandra_Rossi
Active Contributor
0 Kudos

If you don't know what Simple Transformations are, you have to learn. If you just ask for one example with format(ticks), here is one:

Simple Transformation:

<?sap.transform simple?>                                                     
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">        
  <tt:root name="T1"/>                                                       
  <tt:root name="T2"/>                                                       
  <tt:template>                                                              
    <object>                                                                 
      <str name="T1"><tt:value ref=".T1" option="format(ticks)"/></str>      
      <str name="T2"><tt:value ref=".T2" option="format(ticksOffset)"/></str>
    </object>                                                                
  </tt:template>                                                             
</tt:transform>                                                              

ABAP:

    DATA(json) = `{"T1":"\/Date(1418385038000)\/","T2":"\/Date(1418385038992+0000)\/"}`.
    DATA(t1) = VALUE timestamp( ).
    DATA(t2) = VALUE timestampl( ).
    CALL TRANSFORMATION (transfo_name) SOURCE XML json RESULT t1 = t1 t2 = t2.
    cl_abap_unit_assert=>assert_equals(
        act = t1
        exp = CONV timestamp( '20141212115038' ) ).
    cl_abap_unit_assert=>assert_equals(
        act = t2
        exp = CONV timestampl( '20141212115038.9920000' ) ).

 

Accepted Solutions (0)

Answers (0)