pokrak94
pokrak94

Reputation: 202

Changing format of the date in SAPUI5 in DatePicker

I'm trying to get value of DatePicker like so:

var start_date = sap.ui.getCore().byId("start_date_add").getValue();

but I get date in format Jul 29, 2015, I would like to parse it so it is like so: 2015-08-29. Constructor for my date picker:

            new sap.ui.commons.DatePicker({
                id: "start_date_add",
                value: {
                    type: new sap.ui.model.type.Date({
                        pattern: "yyyy-MM-dd",
                        strictParsing: true
                    })
                }
            }),

any help is appreciated

Upvotes: 1

Views: 12998

Answers (2)

Sarath Chandra
Sarath Chandra

Reputation: 189

Hope this might help you.

var start_date = sap.ui.getCore().getModel("appView").getProperty("/dateValue");
var dateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern : "yyyy-MM-dd" }); 
var date = new Date(start_date);
var dateStr = dateFormat.format(date);
console.log(dateStr);

JS Bin example here.

Upvotes: 5

Vinothkumar
Vinothkumar

Reputation: 1

var E_date = new sap.m.DatePicker("E_date", {
        displayFormat : "yyy-MM-dd",
        valueFormat : "yyy-MM-dd",
        value : {
            path : "displayDate"
        }
    });

Upvotes: 0

Related Questions