Home Jquery Datepicker ui with next previous and today date custom button

Datepicker ui with next previous and today date custom button

by therichpost
17 comments
jquery

Hello, welcome to therichpost.com. In this post, I will tell you, Datepicker ui with next previous and today date custom button I personally like jquery very much. Most of my code is full with jquery. When I stuck in php or other language then that stuckness I remove with jquery code. Today I am going to add next previous and today buttons to datepicker.

datepicker-with-custom-buttons

Here is the working code for, Datepicker ui with next previous and today date custom button:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://momentjs.com/downloads/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
 
<script>
$(document).ready(function(){
$('#datepicker').val(moment().format('MM/DD/YYYY'));
    $('#datepicker').datepicker();

   $('.next-day').on('click', function () {
       var date = $('#datepicker').datepicker('getDate');
       date.setDate(date.getDate() +1)
       $('#datepicker').datepicker('setDate', date);
   });

   $('.prev-day').on('click', function () {
       var date = $('#datepicker').datepicker('getDate');
       date.setDate(date.getDate() -1)
       $('#datepicker').datepicker('setDate', date);
   });

   $('.today-date').on('click', function () {
       var date = moment().format('MM/DD/YYYY');
       $('#datepicker').datepicker('setDate', date);
   });
   });
   </script>
<button class="prev-day btn btn-outline-secondary"><i class="fa fa-angle-left" aria-hidden='true'></i></button>
<button class='today-date btn btn-outline-secondary'>Today</button>
<input type='text' id='datepicker'  name='datepicker'>
<button class='next-day btn btn-outline-secondary' ><i class='fa fa-angle-right' aria-hidden='true'></i></button>

 There are so many jquery code, tricks and i will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

You may also like

17 comments

jasmeen April 11, 2018 - 4:25 am

working and It saved my day

Reply
therichpost April 11, 2018 - 8:51 am

Thank you

Reply
Test July 27, 2018 - 5:52 am

How to integrate this in angular 2 in seperate components

Reply
Ajay Malhotra August 14, 2018 - 6:30 am

you can use angular material for this…cheers..

Reply
Mohamad January 31, 2019 - 3:55 pm

How can i show the day and date in the datepicker so that for example it shows as today th, 31/01/2019

Reply
Mohamad January 31, 2019 - 4:00 pm

H r u

Reply
Ajay Malhotra February 3, 2019 - 5:20 am

I am fine, you tell?

Reply
Omar February 1, 2019 - 12:34 am

We have problem where use D dd/mm/yyyy

Reply
Ajay Malhotra February 3, 2019 - 5:21 am

Please tell me issue or error you are getting?

Reply
vkGuna April 1, 2020 - 3:34 pm

This article helped my cause, i just made the textbox hidden so only 3 buttons needed for my case. Thanks

Reply
Ajay Malhotra April 1, 2020 - 4:41 pm

Great..

Reply
yoti Ragond June 9, 2020 - 4:00 am

Hiiiiiiii……..Thanking for this post
My query is date i want date format in dd/mm/yyyy
how can i access this date format.

Reply
Ajay Malhotra June 9, 2020 - 1:59 pm

Simple, you add formart code by above code

Reply
yogi modi August 5, 2022 - 2:12 pm

Thank you!

Reply
therichpost August 5, 2022 - 4:14 pm

You are welcome.

Reply
Christer September 13, 2023 - 7:32 pm

Nice and clear. Thanks. This should have been integrated with the jQuery UI datepicker as an option

Reply
therichpost September 14, 2023 - 5:21 pm

Thanks

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.