-2

I get dates from backend as data format "12/2019" and would like to convert in the format "Dez / 2019" ("Dez" in German, "Dec" in English). Has anyone an idea?

Screenshot of SAPUI5 responsive table asking for date UI format

Snippet from my XML view:

<cells>
  <Text text="{Period}" />
  <!-- ... -->
<cells>

Period is an OData V2 entity property and its EDM type is String.

0

1 Answer 1

2

Try with:

<Text text="{
  path: 'Period',
  type: 'sap.ui.model.type.Date',
  formatOptions: {
    pattern: 'MMM / yyyy',
    source: {
      pattern: 'MM/yyyy'
    }
  }
}" />

Here is a working demo (Click on Run code snippet):

sap.ui.getCore().attachInit(() => sap.ui.require([
  "sap/ui/core/Fragment",
], Fragment => Fragment.load({
  definition: `<Text xmlns="sap.m"
    text="{
      value: '12/2019',
      type: 'sap.ui.model.type.Date',
      formatOptions: {
        pattern: 'MMM / yyyy',
        source: {
          pattern: 'MM/yyyy'
        }
      }
    }"
  />`
}).then(control => control.placeAt("content"))));
<script id="sap-ui-bootstrap"
  src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
  data-sap-ui-libs="sap.ui.core,sap.m"
  data-sap-ui-theme="sap_fiori_3"
  data-sap-ui-async="true"
  data-sap-ui-compatversion="edge"
  data-sap-ui-xx-waitfortheme="init"
></script><body id="content" class="sapUiBody"></body>

Since the EDM Type of Period is String, simply using sap.ui.model.type.Date should be sufficient in this case. If the Type is however Edm.DateTime, which is usually used to represent date values in OData V2, then the type sap.ui.model.odata.type.DateTime should be considered.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.