cancel
Showing results for 
Search instead for 
Did you mean: 

Date conversion format

steph_senita
Explorer
0 Kudos

Hi,

Is there any function or formatter available which converts ANY date format (which a user inputs) into a standard format that OData accepts?

Does a UI5 Application on launchpad tile accept the date in the format which is locally set on the system?

Here's the scenario:

We have created a Travel creation app, in which the date format is set to the following: eg: Jul 7, 2016

So we have used a function that converts the date from this format to a format that the OData accepts using the following code:

  var date_temp = this.byId("DP4").getValue();

  var temp = date_temp.split(" ");

  var month = temp[0];

  var temp1 = temp[1].split(",");

  var day = temp1[0];

  var year = temp[2];

  var months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug',

  'Sep', 'Oct', 'Nov', 'Dec' ];

  for (var j = 0; j < months.length; j++) {

  if (month == months[j]) {

  month = months.indexOf(months[j]) + 1;

  }

  }

  if (month < 10) {

  month = '0' + month;

  }

  datefrom = year + "-" + month + "-" + day;

But the same application displays a different format on the client system (07-Jul-2016). And due to the the function that we used to convert the date fails.

I need a function that extracts the date from any format, and converts it into a standard format. Pls help.

Accepted Solutions (0)

Answers (1)

Answers (1)

santhu_gowdaz
Active Contributor
0 Kudos

What ever the date format, forget about it.

if you call getDateValue() it will returns the system date format so write formatter to convert system date format to oData Date format.

steph_senita
Explorer
0 Kudos

Hi,

Yes, that's right. We will need to format the system date format, ie,

Thu Jul 07 2016 05:30:00 GMT+0530 (India Standard Time) {}


But is there any function that's already present to format the same?

Thanks.

santhu_gowdaz
Active Contributor
0 Kudos

APAIK, No standard methods are available to convert as oData date format. If you are using Util, write your format code there and use it in your application.

Private_Member_15166
Active Contributor
0 Kudos

See. Perhaps these links might be helpful.

naveen_inuganti2
Active Contributor
0 Kudos

This is what I am doing in my code:

Declaration:


<DatePicker change="handleChange" id="DateIN" placeholder="Enter Date ..." valueFormat="MM/dd/yyyy" width="220px"/>

Code from function where I am trying to get date format i.e. required from my Service:


var DateIN = new Date(sap.ui.getCore().byId(this.getView().getId() + "--DateIN").getValue());

DateIN.setDate(DateIN.getDate())

Thanks,
Naveen

santhu_gowdaz
Active Contributor
0 Kudos

Really a good blog regards oData date to system date format,Refer this, you will get easy methods for Date format.

Working with OData Dates and Times | Experiences with SAP Gateway