cancel
Showing results for 
Search instead for 
Did you mean: 
Subscribe

I'm using the sap.m.ObjectStatus as part of my status display on a given agregated list:

in view.js:

var curstat = new sap.m.ObjectStatus({

                                                   //text:  "{CountDate}",

                                                   //text: oController.formatDate('{CountDate}'),

                                                   state: "Success",

                                                   text: {

                                                        parts:[{path:'CountDate'}],

                                                        formatter: 'oController.formatterCountDate'

                                                   }

                                                });

snippet in the controller.js, the format of the CountDate value is, yyyy-mm-ddT00:00:00.  goal is to remove the time part leaving only YYYY-MM-DD.  I don't get any exception thrown and the date does show just not in the format I want.  I feel I'm close but just can't get figure out what I may be over looking.  Thanks in advance for the help.

formatterCountDate:function(t) {

                  try {

                  var d = new Date();

                  var T = new sap.ui.model.type.Date( {

                                                     source : {

                                                     pattern : "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

                                                     },

                                                     pattern : "yyyy,MM,dd",

                                                     style : "medium"

                                                     });

                  d = T.formatValue(t, "string");

                  var D = new Date(d);

                  return D

                  }//try

                  catch(error) {

                    alert(error.message);

                  }

},

0 Likes
View Entire Topic
naveenraj_sap
Active Participant
0 Likes

Hi Jay, can you try with the below code.

Also make sure your CountDate propery in OData model has Edm.DateTime datatype.


formatterCountDate : function (value) {

  if((value!=null) && (value!="0000-00-00"))

  {

  if (value) {

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

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

  }

else {  return value; }

  }

  else return "";

  }

Let me know if you face any issues.

--Naveenraj.

Former Member
0 Likes

Thanks Naveenraj.  This almost worked.  But it keeps returning with the year 1969.  tried to just pass value to oDateFormat.format but it comes back with:

'null' is not an object value.getDay.

Former Member
0 Likes

it seems like, when the date field is empty, even when I say " return ""; ", it forces it to have something and in this case, it returns 1969-12-13.  But the formatting works correctly; able to remove the time part.