cancel
Showing results for 
Search instead for 
Did you mean: 

Datepicker and dateformat

Former Member
0 Kudos

Hi!

I know there´s a lot of threads regarding datepicker and date format, but i haven´t found a solution to my problem yet.

I need to change the format of the datepicker to dd-MM-yyyy. The datepicker is not bound to a model. Here is an example:

var oDatePicker1 = new sap.ui.commons.DatePicker('date1');

oDatePicker1.setYyyymmdd("20100101");

oDatePicker1.setLocale("de");

It outputs 01.01.2010 - how to change this to 01-01-2010?

Kind regards,

Kim

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

var oDatePicker1 = new DatePicker('date1');

oDatePicker1._formatValue(new Date());

oDatePicker1._oFormat = sap.ui.core.format.DateFormat.getInstance(

    {pattern: "dd-MM-yyyy", strictParsing: true, calendarType: sap.ui.core.CalendarType.Gregorian});

     

dont like using internal variable/functions - wrap it as a custom control

Former Member
0 Kudos

Hi - that worked. Thanks a lot! It both formats the date, if the user selects a value in the calender, and the user is able to type a date, using the - . Do you know if there´s a way to accept user input in different formats? Ex. 12-12-2012 and 12/12/2012?

Kind regards,

Kim

Answers (2)

Answers (2)

daniel_ruiz2
Active Contributor
0 Kudos

hi Kim,

Chile date format is the same as the new German date format - not too sure if this is enough for your needs. Case you want to give it a try:

var oDatePicker = new DatePicker({ locale: 'es-CL' });

Hope it helps,
Dan.

saivellanki
Active Contributor
0 Kudos

Hi Kim,

You could use JavaScript replace method. Check this sample: JS Bin - Collaborative JavaScript Debugging

Regards,

Sai Vellanki.