Search code examples
javascriptmomentjsdaterangepicker

Show full month name in Daterange picker


How can I change the month name of daterange picker to full month name? Currently it displays only 3 chars of the month.

https://i.sstatic.net/hAmv0.png

I want to show full month names. I used https://www.daterangepicker.com/ as my template.


Solution

  • Simply set options.locale.monthNames to moment.months(). The months default to moment.monthsShort().

    Here are the default locale settings:

    this.locale = {
      direction: 'ltr',
      format: moment.localeData().longDateFormat('L'),
      separator: ' - ',
      applyLabel: 'Apply',
      cancelLabel: 'Cancel',
      weekLabel: 'W',
      customRangeLabel: 'Custom Range',
      daysOfWeek: moment.weekdaysMin(),
      monthNames: moment.monthsShort(),
      firstDay: moment.localeData().firstDayOfWeek()
    };
    

    // Based on: https://www.daterangepicker.com/#example1
    $(function() {
      $('input[name="daterange"]').daterangepicker({
        opens: 'left',
        locale: {
          monthNames: moment.months()
        }
      }, function(start, end, label) {
        console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
      });
    });
    <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
    <input type="text" name="daterange" value="01/01/2018 - 01/15/2018" />