on 02-27-2021 1:22 AM
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?
Since there is no code, I assume the binding info of the DatePicker is not consistent with the binding info of the Text within the table. It's important to keep them consistent.
If the values are bound with a v2.ODataModel, use:
<DatePicker/Text xmlns="sap.m"
xmlns:core="sap.ui.core"
core:require="{ ODataDateTimeType: 'sap/ui/model/odata/type/DateTime' }"
value/text="{
path: 'EntryDate',
type: 'ODataDateTimeType',
constraints: {
displayFormat: 'Date'
}
}"
/>
Please follow the documented guidelines "Dates, Times, Timestamps, and Time Zones" — must-read for OData V2 and OData V4.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your answer but it didn't work. Where am I doing wrong?
<!--It's a input on my fragmnet-->
<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"/>
</f:content>
</f:SimpleForm>
<cells>
<!--My code-->
<!--<Text text="{ path: 'Tarih', type: 'sap.ui.model.type.Date', formatOptions: { pattern: 'MM/dd/yyyy' } }" />-->
<!--Your code-->
<Text xmlns="sap.m" xmlns:core="sap.ui.core" core:require="{ ODataDateTimeType: 'sap/ui/model/odata/type/DateTime' }" text="{ path: 'Tarih', type: 'ODataDateTimeType', constraints: { displayFormat: 'Date' } }"/>
</cells>
sehergurel The value-property in DatePicker should be also bound with the v2.ODataModel as suggested in my answer.
The above steps are part of the standard approach of dealing with OData binding.
If it requires too many changes in your code, forget all the above steps and try adding `UTC: true` to your Text.
<Text text="{
path: 'Tarih',
type: 'sap.ui.model.type.Date',
formatOptions: {
...,
UTC: true
}
}" />
Boghyon's solution definitely works. It's pretty charming you can stick to Databinding and keep away any coding here.
I am assuming your table is directly binded to odata model
<Table items="{/ListSet}">
Can you confirm
if data save at backend for 5th date ?
if not then issue when you passing data to backend at time only you missing one day.
var vTarih = sap.ui.getCore().byId("dpKayitTarih").getDateValue();
To Solve this you need to do as below
resolveTimeDifference:function(dateTime){
if (dateTime !== undefined && dateTime !== null && dateTime !== "") {
var offSet = dateTime.getTimezoneOffset();
var offSetVal = dateTime.getTimezoneOffset() / 60;
var h = Math.floor(Math.abs(offSetVal));
var m = Math.floor((Math.abs(offSetVal) * 60) % 60);
dateTime = new Date(dateTime.setHours(h, m, 0, 0)); return dateTime;
}
return null;
},
var vTarih = this.resolveTimeDifference(sap.ui.getCore().byId("dpKayitTarih").getDateValue());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are great. Thank you so much. Problem solved.
Can you please share your view binding code for date picker.
If you can't share then can you tell if its live binding with odata model or with local json model.
We have same problem in both type binding above given binding will work if its directly binded from odata model.
if you are first copying data to local model then bindind then you need to apply one formatter also .
let us know how you binded?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used OData Model.
For Tarih (date) field:
My fragment.view
...
<content>
<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"/>
</f:content>
</f:SimpleForm>
</content>
<buttons>
<Button text="{i18n>kaydet}" press="onKayitFrag" type="Transparent"/>
<Button text="{i18n>geri}" press="onGeriFrag" type="Transparent"/>
</buttons>
...
My Worklist.view<Table>
...
<items>
<ColumnListItem>
<cells>
<Text text="{path: 'Tarih', type: 'sap.ui.model.type.DateTime', formatOptions: { strictParsing: true , UTC: true}}"/>
</cells>
</ColumnListItem>
</items>
</Table>
My controller.js/onKayitFrag
onKayitFrag: function() {
var that = this;
var vTarih = sap.ui.getCore().byId("dpKayitTarih").getDateValue();
var sData = {
Tarih: vTarih
};
sap.ui.core.BusyIndicator.show();
this.getView().getModel().create("/ListSet", sData, {
success: function(oData) {
sap.ui.core.BusyIndicator.hide();
that._getKayitDialog().close();
that.onRefresh();
MessageToast.show("Başarılı");
},
error: function(oError) {
sap.ui.core.BusyIndicator.hide();
that._getKayitDialog().close();
MessageToast.show("Başarısız");
}
});
}<br>
Use binding as below it will work
text="{path: 'date', type: 'sap.ui.model.type.DateTime', formatOptions: { strictParsing: true , UTC: true}}
Issue is coming to you because of time zone .Some time server and client have different time zone
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can also refer below code:
<DatePicker id="myDatePicker" placeholder="Enter Date" value="{ path:'/dateValue', type:'sap.ui.model.type.Date', formatOptions: { strictParsing: true, UTC: true } }" />
Riya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.