How to change the date range picker’s date format?

I am using this bootstrap date range picker. I want to change date format date to dd/MMM/yyyy:

<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css" rel="nofollow noreferrer noopener" />

<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>

<script type="text/javascript">
$(function() {
    $("#<%= txtName.ClientID %>").daterangepicker();
});
</script>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you want to present a different format, you need to add a locale object after you run the daterangepicker function. The site doesn’t currently have a list of all the formats it supports, but try this:

$(function() {
    $("#<%= txtName.ClientID %>").daterangepicker({
        locale: {
            format: 'DD/MMM/YYYY'
        }
    });
});

See here for more options: http://www.daterangepicker.com/#config

Method 2

try using this it worked for me

 locale: {
                format: 'YYYY-MM-DD',
                separator: " to "

            },

Method 3

There was actually a bug related to wrong dates being selected.

Here are the details.

Updating to the latest version resolved the locale format bug for me.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x