Hi ,
I'm a Software Engineer.I'm new to VB.NET
My problem is...
I'm coding a time sheet management system.in that user can enter the data upto today.DateTimePicker is allowing future dates also.
How can I restrict that date upto Today.
SO that user can not enter data for tommorow's date.
I need code for this ..
Please send your answers
Thanks in Advance.
Regards
Sunnny
Comments
: I'm a Software Engineer.I'm new to VB.NET
: My problem is...
: I'm coding a time sheet management system.in that user can enter the data upto today.DateTimePicker is allowing future dates also.
: How can I restrict that date upto Today.
: SO that user can not enter data for tommorow's date.
: I need code for this ..
: Please send your answers
: Thanks in Advance.
:
: Regards
: Sunnny
Hi,
Look at >>
http://www.programmersheaven.com/c/MsgBoard/read.asp?Board=39&MsgID=334825&Setting=A9999F0001
View the string created in the code segment i suggest then use something like>>
[code]
Dim timeNow,userTime As Date
timeNow=Now()
'Get user input timeDate
'CDATE converts to dateTime format.
userTime=CDate(InputBox("Enter the date and time please."))
If userTime>TimeNow then
'Warn user
Textbox1.Text="Not a future date or time to be entered please."
Else
'INSERT YOUR CODE HERE.
End If
[/code]
Regards,
Dr M.
Actually there is one more way to solve this problem - use DateDiff () function. This way is a little bit more efficient than Dr.Martin use.
[code]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SecondDate As Date
SecondDate = CDate(TextBox1.Text)
If DateDiff(DateInterval.Day, Now, SecondDate) > 0 Then
With TextBox1
.Focus()
.SelectionStart = 0
.SelectionLength = Len(TextBox1.Text)
End With
End If
End Sub
[/code]