0

I have to controls(date picker,time picker) , I take the values as string, and I want to set them in this object, what can I do?

Note that .Date is declared as dateTime in the table.

dim  DateVal As String
dim TimeVal As String

 With Object

  .Date = ???

End With
2
  • You are "taking" them as string, how and more important, why? If you use a DateTimePicker control it has a Value property that returns a DateTime not a string. Commented Oct 2, 2013 at 8:07
  • I am creating a reminder, the user has to to choose reminder date an time, I pass these values over a webservice method so I receive the values as string. @Tim Schmelter Commented Oct 2, 2013 at 8:11

1 Answer 1

2

You are "taking" them as string, how and more important, why? If you use a DateTimePicker control it has a Value property that returns a DateTime not a string.

So just use that property and don't convert or box the type to object and never convert it to String if you don't want to show it, leave it as what it is, a DateTime variable.

I am creating a reminder, the user has to to choose reminder date an time, I pass these values over a webservice method so I receive the values as string.

Then you're asking how to convert the string to DateTime, use Date.Parse or Date.TryParse:

If the format is common:

Dim dt As Date = Date.Parse(dateString)

If it might be invalid:

Dim dt As Date
If Date.TryParse(dateString, dt) Then
    ' ....
End If

If the format is uncommon or not the same as the current culture(read: http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx):

Dim format = "MMM dd, yyyy" ', e.g.: Oct 02, 2013
Dim dt As Date
If Date.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, dt) Then
     ' .... 
End If
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.