fragaria / angular-daterangepicker

Angular.js wrapper for dangrossman/bootstrap-daterangepicker
MIT License
519 stars 372 forks source link

custom range does not respect date format #224

Closed beatelite closed 5 years ago

beatelite commented 7 years ago

Hi, I have this in my controller:

    $scope.opts = { 

        format: 'YYYY/MM/DD',
        ranges: {
            'This Month': [moment().startOf('month').format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
            'Today': [moment().format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
            'Yesterday': [moment().subtract(1, 'day').format("YYYY-MM-DD"), moment().subtract(1, 'day').format("YYYY-MM-DD")],
            'Last 7 Days': [moment().subtract(6, 'days').format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
            'Last 30 Days': [moment().subtract(29, 'days').format("YYYY-MM-DD"), moment().format("YYYY-MM-DD")],
            'Last Month': [moment().subtract(1, 'month').startOf('month').format("YYYY-MM-DD"), moment().subtract(1, 'month').endOf('month').format("YYYY-MM-DD")]
        }

    };  

I need the date format to be YYYY/MM/DD. Selecting a predefined range works perfectly. I get the right startDate and endDate values in YYYY/MM/DD thanks to moment.

However, when a user selects custom range and picks a start and end date, I see this in the response objects for start and end dates:

endDate: Fri Sep 09 2016 23:59:59 GMT-0700 (PDT)

startDate: Thu Sep 08 2016 00:00:00 GMT-0700 (PDT)

How do I get the same YYY/MM/DD format for custom ranges?

edionmelarosa commented 7 years ago

Try put format on locale object.

locale: { format: 'YYYY/MM/DD' }

or on your view: options="{locale: {format: 'YYYY/MM/DD'}}"