cancel
Showing results for 
Search instead for 
Did you mean: 

Sapui5 date one day missing

0 Kudos

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
boghyon
Product and Topic Expert
Product and Topic Expert

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.

0 Kudos

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>
boghyon
Product and Topic Expert
Product and Topic Expert
0 Kudos

sehergurel The value-property in DatePicker should be also bound with the v2.ODataModel as suggested in my answer.

  1. Add the missing relative value-binding (i.e. without a leading slash in the beginning) to your DatePicker, same as with <Text text="{...}"/>.
  2. When the user opens the dialog, create a binding Context with myODataModel.createEntry as described in the topic Creating Entities and set the created Context instance with myDialog.setBindingContext.
  3. After the user enters the data and presses [Send], submit the newly created entry to the backend with myODataModel.submitChanges. The Table will be refreshed automatically with the new data (unless refreshAfterChange is disabled).

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
  }
}" />
0 Kudos

I've tried many methods like this but unfortunately it doesn't work.

petergilberg
Participant

Boghyon's solution definitely works. It's pretty charming you can stick to Databinding and keep away any coding here.