Skip to Content
avatar image
Former Member

Datepicker and dateformat

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 19, 2015 at 07:32 PM

    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


    Capture.PNG (1.5 kB)
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • avatar image
    Former Member
    Oct 20, 2015 at 03:27 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 19, 2015 at 11:56 AM

    Hi Kim,

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

    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded