Good day to all
First of all, an apology, use Google translator to post my problem.
I would like to put the following column text in a date format “dd / mm / yyyy”.

The data given to me through an Odata created for the use of the app is a String, so I don't know if that is a problem to be able to format it.
I have researched a little, but I have not been able to find something that can help me or work correctly.
This is part of my code:
XML View:
<Table inset="false" items="{/d/results}" id="table0" width="auto">
<items>
<ColumnListItem type="Active" id="item1">
<cells>
<Text text="{Xao}" id="text7"/>
<Text text="{Xoccupant}" id="text8"/>
<Text text="{Validfrom}" id="text9"/>
<Text text="{Validto}" id="text10"/>
</cells>
</ColumnListItem>
</items>
<columns>
<Column id="column0" >
<header>
<Label text="Tipo" id="label0"/>
</header>
</Column>
<Column id="column1">
<header>
<Label text="Ocupante" id="label1"/>
</header>
</Column>
<Column id="column2">
<header>
<Label text="Fecha de Apartado" id="label2"/>
</header>
</Column>
<Column id="column3">
<header>
<Label text="Fecha de Finalización" id="label3"/>
</header>
</Column>
</columns>
</Table>
Controller.js:
var serviceURL4 = "/sap/opu/odata/sap/ZGESRE_SRV/SCheaderSet?$filter= (AotypeAo eq 'US' and Nivel2 eq '" + this._ciudad + "' and Nivel3 eq '" + this._Edificio + "' and Nivel4 eq '" + this._Piso + "')";
var JsonModel4 = new sap.ui.model.json.JSONModel();
this.getView().byId("table0").setModel(JsonModel4);
JsonModel4.loadData(serviceURL4, null, false);
JsonModel4.getProperty("/d/results");
Any ideas or any advice on how I could modify or change the format to put the date?
Thank you for your answers.
Greetings.
Edson.
Request clarification before answering.
hi,
since you are using binding, you can mention the type of the bining parameter and provide format options.
Please note that the source->pattern, is the Date pattern in ABAP
and the "pattern" property is for the output pattern for the display.
You can use something like this:
<Text text="{
path: 'Validfrom',
type: 'sap.ui.model.type.Date',
formatOptions: {
source: {
pattern: 'yyyyMMdd'
},
pattern: 'dd/MM/yyyy'
}
}"/>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Edson,
You can write below code and format the date your getting from backend.
var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern:"dd/MM/YYYY" });
var format = dateFormat.parse("20191203");
var dateFormatted = dateFormat.format(format);Regards,
Manjunatha Devadiga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Edson,
Please include the following either one of the following properties to in the index.html file
data-sap-ui-compactVersion="edge"
or
data-sap-ui-bindingSyntax="complex"

Ref: https://openui5.hana.ondemand.com/#/topic/91f0652b6f4d1014b6dd926db0e91070
I hope it will solve the error.
with regards
Sudhir
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should use formatter for this thing.
Please refer to the following blogpost for the same.
https://sapyard.com/sapui5-list-control-using-formatters/
and for the formatter function, you can use the following code:
formatDate: function (oDate) {
if (oDate) {
var date = oDate.substring(4, 6) + "/" + oDate.substring(6, 8) + "/" + oDate.substring(0, 4);
return date;
}
return "";
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anmol.
Thank you very much for your response and reference of the formatting issue.
I must say that it worked, only that it fits me in the form of MM / DD / YYYY, and I have tried to modify it so that DD / MM / YYYY is changed by changing the data within substring, but it still does not work.
var date = oDate.substring(6, 😎 + "/" + oDate.substring(4, 6) + "/" + oDate.substring(0, 4);
Will you have any advice or any way to spend the months a day?
Regards.
Edson.
Hi Anmol.
Thank you very much for your response and reference of the formatting issue.
I must say that it worked, only that it fits me in the form of MM / DD / YYYY, and I have tried to modify it so that DD / MM / YYYY is changed by changing the data within substring, but it still does not work.
var date = oDate.substring(6, 😎 + "/" + oDate.substring(4, 6) + "/" + oDate.substring(0, 4);
Will you have any advice or any way to spend the months a day?
Regards.
Edson.
Hi Edson
It's strange that var date = oDate.substring(6, 😎 + "/" + oDate.substring(4, 6) + "/" + oDate.substring(0, 4); Isn'tworking.
Can you please use console to check the date before and after the formatting using console.log(oDate) and console.log(date) and reply me with the output?
Regards
Anmol
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.