asp.net textbox datepicker from jquery

RAVI 1,076 Reputation points
2024-03-12T05:22:22.5166667+00:00

Hello

This is my jquery for date

    
 <script>
        $(function () {
             $("#TextBox2").datepicker({
                dateFormat: "dd-M-yy",
                minDate: new Date('2018/08/01'),
                changeYear: true,
                changeMonth:true,
                yearRange: '2018:2030',
                maxDate: "+0M +0D"                 
        });
        });
</script>   

Here I Need Two Options For Example

  1. If A Current Month Is Below 5th Date It Should Open Previous Month Last 6 Days.
  2. If Current Month Is Greater Then 5th Date It Should Dispaly Select Date As From Month First Date Only.
Microsoft 365 and Office Development Office JavaScript API
Developer technologies ASP.NET Other
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2024-03-12T06:30:49.0233333+00:00

    Hi @RAVI,

    You can try using the code below.

     <script type="text/javascript">
         $(function () {
             var date = new Date();
             if (date.getDate() > 5) {
                 date.setDate(1);
             }
             else {
                 date.setDate(-6);
             }
             $("#TextBox2").datepicker({
                 dateFormat: "dd-M-yy",
                 minDate: date,
                 changeYear: true,
                 changeMonth: true,
                 yearRange: '2018:2030',
                 defaultDate: date,
             });
         });
     </script>
    

    If A Current Month Is Below 5th Date It Should Open Previous Month Last 6 Days.

    User's image

    If Current Month Is Greater Then 5th Date It Should Dispaly Select Date As From Month First Date Only.

    User's image

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.