0
votes

From backend, the date format is like above, and I want to format the date using formatter into a real date. I got a datepicker in my detailpage and the datepicker wants a real date, to show it up.

So I tried a bit, but I can't get it to work. So maybe someone can help me or guide how to do it? I know I can format the date in the backend but I need it that way like above as a string.

2
If backend is sending the date object then it will be easy to format at the UI side. Else need to use the formatter, and convert the string to date object and show formatted date to UI. At least tell to send the date format to yyyy/mm/dd format, so that it is easy to format in UI side.inizio

2 Answers

1
votes

If you are using sap.m.DatePicker here an example:

<DatePicker
        id="DP2"
        value="2014-03-26" valueFormat="yyyy-MM-dd" displayFormat="long"
        change="handleChange"
        class="sapUiSmallMarginBottom"/>

there's the valueFormat and displayFormat attribute to shape date format as you want.

  • valueFormat is the date format you want when user click on date and you can grab in oEvent.

  • displayFormat is the date format you want to show.

Reference SAPUI 5 DatePicker example

0
votes

Hi you can create a date from teh string you receiving by using below js code

 getDate:function(value){
//value is your string from backend "20120515"
if(value){
        var dateString  = value;
        var year        = dateString.substring(0,4);
        var month       = dateString.substring(4,6);
        var day         = dateString.substring(6,8);

        var date        = new Date(year, month-1, day);

    return date; // Keep in mind the date returned will only be correct if the string is passed in above format
    }
}

You can use the above function in formatter.js file and can use in datepicker as below

<DatePicker value="{path:'modelDateProperty', formatter:'.formatter.getDate', }" />

I hope this helps