Skip to Content

Create JSON with date in Unix Time format

Jan 02, 2017 at 02:56 PM


avatar image

I need to create a JSON document for a REST web service call. In this JSON there is a date field that needs to formatted in Unix Time (seconds since 1st of January 1970)

Request: [
} ]

The data is coming from an ABAP Structure:

Is there a way to create such a JSON directly via e.g. CALL TRANSFORMATION or is there at least a method/function module to convert ABAP dates to UNIX Time?

10 |10000 characters needed characters left characters exceeded

seconds or milliseconds? Probably the second one (AKA "ticks")

* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Sandra Rossi Jan 02, 2017 at 04:47 PM

You may create an ST transformation with <tt:value ... option="fmt(ticks)"/> (cf ST - option, Mapping Rules) which will generate "Date":/Date(1418342400000)/

If you don't want this format, then you need to use an additional ABAP field that you calculate yourself or call a method from within ST (CONVERT DATE ... INTO TIME STAMP ...)

You may generate automatically JSON from ABAP, using writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ), and CALL TRANSFORMATION ... RESULT XML writer (cf SCN blog post ABAP and JSON, by Horst Keller, on 2013/01/07)

Show 6 Share
10 |10000 characters needed characters left characters exceeded

Dear Sandra,

thank you for your reply. I can't get the transformation working as described. In the documentation you linked it says option="format(ticks)" so I tried the following transformation with 4 different version of the format option.
For all versions I get a warning like "illegal value 'fmt=(ticks)'" and in the resulting JSON (created with cl_sxml_string_writer) the date is always formatted as YYYY-MM-DD.

<?sap.transform simple?>
<tt:transform xmlns:tt="">
  <tt:root name="T_DATA"/>
      <tt:loop ref="T_DATA">
          <str name="ID">
            <tt:value ref="$"/>
          <num name="NumDateFmt">
            <tt:value ref="$" option="fmt=(ticks)"/>

          <str name="StrDateFmt">
            <tt:value ref="$" option="fmt=(ticks)"/>

          <num name="NumDate">
            <tt:value ref="$" option="format=(ticks)"/>

          <str name="StrDate">
            <tt:value ref="$" option="format=(ticks)"/>

Kind regards!



I apologize for the missing documentation in Release 7.40.

It was delivered with Release 7.50.

New features were added in Release 7.51.




No it works fine. Thank you for your help!


Hi Sandra,

In my response I am receiving the timestamp in JSON format i.e., /Date(1462881866000)/. How do I convert this to ABAP format i.e. to YYYYMMDD format?

Thank you.



Same as already said/documented, but direction from JSON to ABAP cf Horst Keller's blog (see reference above). If you need further assistance, please open a new question.