954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Disabling dates before current date of a datetimepicker control

Hey Everyone

Is it possible to disable the dates that appear before todays date in a dateTimePicker control?

I want to put in some validation so that my users can only select days in the future...ie a future appointment date

Any ideas ?


Thanks

Elmo_loves_you
Junior Poster in Training
85 posts since Mar 2008
Reputation Points: 30
Solved Threads: 0
 

hey,
maybe this will be helpful...try something like (for validation)

if dtpkr.value < dtpkr.value.date then

display error

else

yourvariable = dtpkr.value

end if

sorry im a beginner to but i think this should work, Gd Lk

hisheeraz
Newbie Poster
9 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

I'm not certain what version of Visual Studio you're using - I'm still using 2003 however we have purchased and installed 2008 and I am preparing to start using it in the next week or two..

however in 2003 in your toolbox you have the required field validator you can use - you set the validator to validate the date textbox or whatever you want and in the operator field of the properties you chose greater than or greater than equal if you want them to be able to enter todays date.

you can then insert a validation summary from the toolbox and in error message of your validator you can list the message you want to place in that summary area. So you can say "Date can not be prior to today" and it will tell them what's wrong. You can even insert a second validator and make it required so it will make sure it's also not blank and so on.

you can mess with settings like make the color red etc.

Then in your code you can put in a valid fields check - an example I've used for one of mine is here

Private Sub ValidFields()

        Dim strError As String = "Validating Request."

        Try

            cpvRequestedDueDate.ValueToCompare = DateTime.Now.Today.ToShortDateString

            rfvReqUser.Validate()
            rfvTitle.Validate()
            rfvDescription.Validate()
            rfvPriority.Validate()
            cpvRequestedDueDate.Validate()
            cpvRequestedDueDate2.Validate()
            rqvDueDate.Validate()

        Catch ex As SqlException
            PageUtil.ShortProcessErrors(ex, Session, Me, strError)
            PageUtil.ShowError(Page, strError)
        Catch ex As Exception
            PageUtil.ShortProcessErrors(ex, Session, Me, strError)
            PageUtil.ShowError(Page, strError)
        Finally
        End Try

    End Sub


in the above example - rqvDueDate is one validator that was inserted to validate due date. That name was set in the id field of the properties.

rapture
Posting Whiz in Training
294 posts since Jul 2007
Reputation Points: 155
Solved Threads: 41
 

am realy desperate guys i need the code to control users picking up unwanted date or time. thanx

SKARY
Newbie Poster
2 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

sorry, i forgot something. i am uing asp.net with vb

SKARY
Newbie Poster
2 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

datetimepicker.mindate = now

this should do the trick :)

jay200032
Newbie Poster
11 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You