cancel
Showing results for 
Search instead for 
Did you mean: 

Convert date format in SAPUI5

arindam_samanta
Participant
0 Kudos

Hi Expert,

I want to convert date format as SAP input format. In SAPUI5 I have used below code:

<Label id="lbl1" text="Enter Date" visible="true" required="true" design="Bold"> </Label>

       

<DateTimeInput id="dtDT" type="Date" change="dateFunc"></DateTimeInput>

The input format is: FEB 7,2014.

I need to convert this format to YYYY/MM/DD and display in a alert method as a message.

How to convert the input date format into YYYY/MM/DD format.

Any possible sollution would be accepted gratefully.

Thanks & Regards,

Arindam Samanta.

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member182650
Contributor

Hi Arindam,

You could use:

https://sapui5.netweaver.ondemand.com/sdk/docs/api/symbols/sap.ca.ui.model.format.DateFormat.html



var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern : "YYYY/MM/DD" });  

var dateFormatted = dateFormat.format(yourDate);

Kind regards

former_member293602
Active Participant
0 Kudos

Hi,

the developer guide has a nice description at the bottom of the page SAPUI5 SDK - Demo Kit too.

Regards, Frank

rauf_shaikh
Active Participant
0 Kudos

Hi Angel,

The same thing can be implemented in view. In case if you have idea about that can you please explain.
I remember it was something like below:
{

     'path' : 'Zname',

     'formatter' : '..formatter lib path'

}

Regards,

Rauf

Former Member
0 Kudos

This message was moderated.

surendra_pamidi
Contributor
0 Kudos

Hi Arindam,

Use split function to seperate the date. Use two times split function. First time seperate the comma(,) and second time for space. So you will get  in an array. Use them to display in your format.

how to split a string in javascript - Stack Overflow

Tryit Editor v1.8

For example, Use like this.. array[0]+"/"+array2[0]+"/"+array2[1] in the output format.

former_member184867
Active Contributor
0 Kudos

Hi Arindam,

Here is a working sample you may refer to..

You may have a look at some more useful Date format examples here

If you are consuming date from OData service , this blog by John Patterson is a must read. 

Regards,

Atanu