cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Date Formatting

Former Member
0 Likes
6,765

Hi All,

I created a table with XML view.

This is how i have binded.

<items>

<ColumnListItem>

<cells>

          <Text

            text="{empModel>Empno}" />

          <Text

            text="{empModel>Fname}" />

          <Text

            text="{empModel>Lname}" />

          <Text

            text="{empModel>Addrs}" />

          <Text

            text="{empModel>Desgn}" />

          <Text

            text="{empModel>Dob}" />

</cells>

</ColumnListItem>

    </items>



But my date format which is coming from gateway is in this format "2015-05-05T05:13:19.3167890".


I want to display it as 05-05-2015.


I also have a datepicker and in that datepicker date format is not selected in this format. So basically how i can perform the POST operations?


I am a beginner so if possible attach a simple code for reference.


Thanks in advance.

View Entire Topic
0 Likes

Hi,
you can try 2 options
1. use type and formatOptions
SAPUI5 Explored

2. use formattrer function

SAPUI5 - XML view and Formatter | SCN

Former Member
0 Likes

Hi,

I tried like this.

          <Text text="{

                     path: '{empModel>Dob}',

                     type: 'sap.ui.model.type.DateTime',

                     formatOptions: {

                           style: 'short',

                           source: {

                                         pattern: 'yyyy/MM/dd'

                                         }

                                                }

}" />


But it didn't worked. It's showing me blank column.


May you provide me a simple example.

0 Likes

Hi Raghu,
please, try that
Code in view


<Text text="{path: 'empModel>Dob',

             formatter: '.formatDate'}"

/>

function in controller:


formatDate : function(v) {

     jQuery.sap.require("sap.ui.core.format.DateFormat");

     var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "dd-MM-YYYY"});

     return oDateFormat.format(new Date(v));

}

Regards,
Raman

Qualiture
SAP Mentor
SAP Mentor
0 Likes

Well, you forgot to specify the input pattern Also, you used brackets surrounding the model field you are binding, but this is incorrect too (you are already binding)

Change it to

<Text text="{

    path: 'empModel>Dob',

    type: 'sap.ui.model.type.Date',

    formatOptions: {

        source: {

            pattern: 'yyyy-MM-ddTHH:mm:ss.AAAAAAA'

        },

        pattern: 'yyyy/MM/dd'

    }

}" />

Former Member
0 Likes

Hi    ,

First of all thank you.

I tried your code but i would like to know here you have used something like this.

formatter: '.formatDate'}"

I see a dot here but in controller you are using just formatDate.

Why you have used dot here??

Former Member
0 Likes

Hi 

I tried your code but i am getting following error.

Please suggest.

And Thanks a lot.

Former Member
0 Likes

pattern: 'yyyy-MM-ddTHH:mm:ss.AAAAAAA', I am getting source pattern like this.


here what is the meaning of .AAAAAAA??


Suppose i have a calendar as input then how i will append this value to my formatter?


Thank you.

Qualiture
SAP Mentor
SAP Mentor
0 Likes

You probably did something wrong then... works for me in this working example: Edit fiddle - JSFiddle

Qualiture
SAP Mentor
SAP Mentor
0 Likes

Since your example date was "2015-05-05T05:13:19.3167890", I assumed the last 7 digits were milliseconds.

But obviously, milliseconds can only be maximum of 3 digits (hence the milli) so i'm not sure what those last 7 digits are. If you look at the example I just provided, you'll see a correct date

0 Likes

You are welcome:)
UI5 uses this syntax for binding. Dot means a local function/type.
Read more SAPUI5 SDK - Demo Kit

Former Member
0 Likes

Hi,

I checked your link and it's working.

But in my case it is not working.

What may be the probable error??

Please suggest.

Thanks a lot.

Qualiture
SAP Mentor
SAP Mentor
0 Likes

As I mentioned, the date you provided has some strange 7 digits at the end where normally only 3 are possible. Can you explain what those 7 digits are, and where they come from?

0 Likes

Perhaps, number 19.3167890 means seconds in float format.

Try pattern 'yyyy-MM-ddTHH:mm:ss.sssssss'.

Former Member
0 Likes

It's coming from my Gateway only. Should i contact to gateway developer?

Qualiture
SAP Mentor
SAP Mentor
0 Likes

No, is right, it is seconds in float format.

Source pattern pattern: 'yyyy-MM-ddTHH:mm:ss.sssssss' should work fine

Former Member
0 Likes

WOW Great. Thanks a lot. Now your code is working.

This post contains two correct answers, but i may only choose one as correct.

former_member197827
Participant
0 Likes

Hi Robin,

From OData service I am receiving the date in following format:

/Date(1354665600000)/"

and I am binding it to sap.ui.commons.DatePicker.

So what should be the source pattern in my case?? I dont want to use formatter function as  it is not updating the changed values in model (I am using json model).

Thanks and Regards,

Sagar