DateTime picker

Adeel Mirza 121 Reputation points
2021-12-23T12:09:19.417+00:00

I am using this source code to implement calendar control. But its not taking the data format is dd/mm/yy. Why?

<script type="text/javascript">
        $(function () {
            var date = new Date();
            var currentMonth = date.getMonth();
            var currentDate = date.getDate();
            var currentYear = date.getFullYear();
            $('#ContentPlaceHolder1_txtVisitingDateTill').datepicker({
                dateFormat: 'dd/mm/yy',
                maxDate: new Date
            });
            return currentDate + '-' + currentMonth + '-' + currentYear;
        });
    </script>
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. cristopheB 551 Reputation points
    2021-12-23T14:09:52.643+00:00

    Hello @Adeel Mirza

    try something like this , your need to initialize the date format
    var date = $('#datepicker').datepicker({ dateFormat: 'dd-mm-yy' }).val();

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2021-12-24T03:15:36.783+00:00

    Hi @Adeel Mirza ,
    For the boot date picker, you must use the following code:

    $( ".datepicker" ).datepicker({  
        format:'yyyy-mm-dd',  
         maxDate: new Date()  
    });  
    

    For jquery datepicker, the following code must be used:

    $( ".datepicker" ).datepicker({  
            dateFormat:'dd-mm-yy',  
            maxDate: new Date()  
         });  
    

    So you must know which date picker you are using, this can finally solve your problem, hope this helps you.
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.