cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sapui5 date one day missing

0 Likes
8,537

I want to show the date I got with DatePicker in a section in a table. But the date is missing 1 day.


I tried many methods:
https://answers.sap.com/questions/409976/sap-webide---ui5---date-field-is-not-showing-corre.html

https://answers.sap.com/questions/323063/date-value-is-getting-reduced-by-one-day-while-pas.html

But it didn't work. What is your suggestion?

View Entire Topic
former_member450774
Participant
0 Likes

Hi,

Use the below sample code for reference.

In XML view:

<DatePicker id="SubmissionDate" value="{path: '/SubmissionDate', type:'sap.ui.model.type.Date', formatOptions:{ pattern : 'yyyy-MM-dd'}}" width="auto" displayFormat="medium" enabled="true" visible="true" valueFormat="yyyyMMdd" required="false"/>

In controller:

var sStartDt = new Date(this.byId("SubmissionDate").getValue());

or

var sNStartDt = (sStartDt.getFullYear()).toString()+'-' +(sStartDt.getMonth()+ 1).toString()+'-'+(sStartDt.getDate()).toString()+"T00:00:00Z"

Hope it helped you!

Rajesh

0 Likes

Can you explain in more detail how to I use this?

former_member450774
Participant
0 Likes

Hi,

Inside simpleform change the datepicker code to below.

<f:SimpleForm editable="true" layout="ResponsiveGridLayout" labelSpanXL="3" labelSpanL="3" labelSpanS="12" adjustLabelSpan="false" emptySpanXL="4" emptySpanL="4" emptySpanM="4" emptySpanS="0" columnsXL="1" columnsL="1" columnsM="1" singleConteinerFullSize="false"><f:content><DatePicker id="dpKayitTarih" value="{path: '/SubmissionDate', type:'sap.ui.model.type.Date', formatOptions:{ pattern : 'yyyy-MM-dd'}}" width="auto" displayFormat="medium" enabled="true" visible="true" valueFormat="yyyyMMdd" required="false"/></f:content></f:SimpleForm>

inside the controller , get the date value as below.

var vTarih =  new Date(this.byId("dpKayitTarih").getValue());

or 
var vTarihDat =  new Date(this.byId("dpKayitTarih").getValue(
var vTarih = (vTarihDat.getFullYear()).toString()+'-' +(vTarihDat.getMonth()+ 1).toString()+'-'+(vTarihDat.getDate()).toString()+"T00:00:00Z"