Skip to Content
0

Date value is getting reduced by one day while passing it from UI5 application to Gateway system

Oct 04, 2017 at 09:36 AM

556

avatar image
Former Member

Hi Experts,

I have a UI5 application where i am passing a date value to a GET_ENTITYSET method of OData (V2) service. Data type of property is Edm.DateTime.

The problem is, in gateway system while debugging GET_ENTITYSET method, i observed that date value is getting reduced by one day. I suppose the problem is with timezone conversion because the UI5 client and gateway server are in different timezones.

Kindly help me with this problem.

Thanks,

Rahul

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

avatar image
Former Member Oct 05, 2017 at 12:50 PM
2

Hi Rahul,

you may set formatOptions:{UTC:true} when working with Time between frontend and backend, so that the Timezone will be calculated correctly by UI5.

Ex:

 {
  path: 'ChangeDateTime',
  type: 'sap.ui.model.type.DateTime',
  formatOptions: {UTC:true}
 }
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

I've just noticed that you're passing the date from the controller.
You can set the parameter UTC to true in the method "format".

I borrow the example above from Amit:

var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({
          pattern: "yyyy-MM-dd"
});
oDate = dateFormat.format(new Date(yourDate), true);

https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.core.format.DateFormat

0
avatar image
Former Member Oct 04, 2017 at 10:01 AM
1

Hi Rahul,

There is some time zone issue while passing Date to backend, however you can use below trick to pass same date to backend.

var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({
          pattern: "yyyy-MM-dd"
});
oDate = dateFormat.format(new Date(yourDate));
oDate = oDate + "T00:00:00";

Regards,

Amit

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thanks Amit for your reply, will try this.

0
Former Member

Amit, i tried with above manipulation of date, but it is still not working. I am passing the date as filter value to odata service.

0
Former Member

Hi Rahul,

Strange it is not working for you,
can you please share your code snippet and request payload of network tab in debug mode.

Regrads,
Amit

0
Arjun Biswas Oct 05, 2017 at 04:57 AM
-1

You can also use the SY-DATUM in ABAP side. SY-DATUM gives the current date.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

We don't want current date, we want the same date which was passed from UI5 client application.

0
Joseph BERTHE Oct 09, 2017 at 12:18 PM
0

The ui5 program send date in UTC +00H00 so in the back end system you should make the conversion when you parse the date with the statement

Convert date time....

Regards

Share
10 |10000 characters needed characters left characters exceeded