You must Sign In to post a response.
  • Category: Visual Studio

    How to disabled particular dates in datetimepicker vb.NET


    Are you looking for a way to disabled particular dates in datetimepicker using vb.NET ? then read this thread to know how to disable it



    Hi All,

    i have a datetimepicker in my module.
    From date and To date in Windows form.

    For ex
    -
    i select 01-08-2014 as from date,
    then select 08-08-2014 as to date, and insert into sql.
    Records Saved.

    For the next time, while enter new entry, the existing selected from 01-08-14 inbetween 08-08-2014, this 8 days, should enable false. Means, user not allowed to enter the same inbetween dates.

    Give me solution with code.


    Regards,
    Ramkumar G.R
  • #750577
    Hello Ramkumar,

    What control you have used to pick a date in your application?

    Regards,
    Nirav Prabtani (Senior Web Developer)
    Email : niravjprabtani@gmail.com
    blog : niravprabtani.blogspot.in

  • #750579
    I don't think there is a way where you can disable certain days but you may automatically change its value when user selects new date in the MonthView control.
    in either case you need to put some validation when user select that dates.

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #750596
    instead of disabling the dates in the datetime picker control you can validate the selected date to make sure that the date selected is valid. For example in the below code i am displaying a message if the selected date is today's date warning the user that they cannot select today's date. you can also handle the validating event of the datetimepicker control to disallow user from selecting a particular date as shown in the following code at the end.

    private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
    {
    if(dateTimePicker1.Value.Date == DateTime.Now.Date)
    {
    MessageBox.Show("Cannot select todays date");
    }
    }

    private void dateTimePicker1_Validating(object sender, CancelEventArgs e)
    {

    }

    Miss. Jain
    Microsoft Certified Technology Specialist in .Net

  • #750616
    Hi Ramkumar,
    For this purpose you can use JQuery date picker and using javascript/Jquery you can disable some specific dates from the calender.
    Add a textbox like below-

    <asp:textbox id="datepicker" runat="server"></asp:textbox>

    and add a javascript like below-

    <script type="text/javascript">
    var Alldays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
    var disableDates = ["2014/09/06", "2014/09/28", "2014/09/29"]; // yyyy/MM/dd
    var disableDays = ["Saturday", "Sunday"];
    function ShowDisableDates(date) {
    ymd = date.getFullYear() + "/" + ("0" + (date.getMonth() + 1)).slice(-2) + "/" + ("0" + date.getDate()).slice(-2);
    day = new Date(ymd).getDay();
    if ($.inArray(ymd, disableDates) < 0 && $.inArray(Alldays[day], disableDays) < 0) {
    return [true, "enabled", "Book Now"];
    } else {
    return [false, "disabled", "Sold Out"];
    }
    }
    $(function() {
    $("#datepicker").datepicker({beforeShowDay:ShowDisableDates});
    });
    </script>

    For more details, go through the below link-
    http://www.aspdotnet-suresh.com/2012/11/disable-specific-dates-days-in-jquery.html
    Try this. It will be helpful to you.

    Thanks,
    Ashutosh Jha
    http://tricksroad.com

  • #750700
    On the page load you can set the dates as below.




    dateTimePicker1.MinDate = DateTime.Now;

    dateTimePicker1.MinDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 2);

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • Sign In to post your comments