![]() So next time, while using setDate() method remember these little but useful things.įeel free to contact me for any help related to jQuery, I will gladly help you. ![]() You can customize the date format and language, restrict the selectable date ranges and add in buttons and other navigation options easily. Use "y" for years, "m" for months, "w" for weeks, "d" for days.įor 1 month from current date, $('#txtDate').datepicker().datepicker('setDate', '+1m') įor 1 year from current date, $('#txtDate').datepicker().datepicker('setDate', '+1y') įor 1 month and 7 days from current date, $('#txtDate').datepicker().datepicker('setDate', '+1m +7d') setDate show widget Events The jQuery UI Datepicker is a highly configurable plugin that adds datepicker functionality to your pages. If you want to set it to current date then you can pass 'today' as argument. Pass date object which needs to be set as an argument to setDate () method. However, this button functions a little differently than I expected. jQuery UI Datepicker : Set Current Date by vikas To set current date in control to which jQuery UI datepicker bind, use setDate () method. By setting the showButtonPanel option to true, you get a button that takes you to today's date. The date is not updated and shows the date selected in step 1. See date on the calendar as specified in step 2. Use datepicker API to set date to a different date using setDate function. It's pretty easy to implement and offers a lot of flexibility in terms of customization. Using the UI, select datepicker then select a date. You can also pass this in weeks, month, years or combination of any of these. The jQuery UI Datepicker widget is a handy way to add a calendar control to a web page. This code will set the date as " 1", considering today is " ". Consider below jQuery code, $('#txtDate').datepicker().datepicker('setDate', '+7') Setting the minimum / start date example In above examples, the current, past or future date can be selected. You can also pass this in weeks, month, years or combination of any of these. The format of the date and time can be set quite easily, as you can see in the jQuery code: format: ‘dddd DD MMMM YYYY HH:mm’ Set the format as per locale or requirement of the website. $('#txtDate').datepicker().datepicker('setDate', '') īut you can also pass number of days from today which you want to set as date. Consider below jQuery code, ('txtDate').datepicker ().datepicker ('setDate', '+7') This code will set the date as ' 1 ', considering today is ' '. $('#txtDate').datepicker().datepicker('setDate', new Date()) SetDate() method takes 'date' as argument but this argument either can be date object or string object. But there are few interesting things which you can also do with setDate() method which you might not be knowing. Add a Solution 1 solution Solution 1 try var d new Date () var currMonth d.getMonth () var currYear d.getFullYear () var startDate new Date (currYear, currMonth, 1 ) ( 'datepicker' ).datepicker () ( 'datepicker' ). ![]() Earlier today, I posted about " How to Set Current Date in jQuery UI Datepicker" using setDate() method provided by jQuery UI Datepicker library. ![]()
0 Comments
Leave a Reply. |