What does this #1/1/1900# means?

sha_shivani

Member
Joined
Sep 28, 2006
Messages
11
Programming Experience
1-3
I am new in programming.Can anyone please tell me what is it returning?

Private ReadOnly Property DueDateFilter() As Date
Get
If IsDate(txtDueDate.Text) Then
Return CType(txtDueDate.Text, Date)
End If
Return #1/1/1900#
End Get
End Property


What does this #1/1/1900# means?
 
If the value in txtDueDate.Text is a Date then it will convert it to Date and immediately return it (Note that the commands following the Return statement will not be executed).
If the value in txtDueDate.Text is not a Date then it will return #1/1/1900#, the Date representation of jan 1 1900.
 
That's actually poor code. The IsDate function will attempt to parse the String to a Date in order to determine whether it is a valid date or not. If it fails it throws an exception and returns False. If it succeeds it returns True. That code then parses the same String a second time if it succeeds. It would be better to do this:
VB.NET:
Try
    Return CDate(txtDueDate.Text)
Catch
    Return #1/01/1900#
End Try
better still would be to use a DateTimePicker rather than a TextBox and never even have to parse any strings at all.
 
Back
Top