5

I have a function that have parameter for DateTime

   AddNewRowToTable(....,DateTime ExpDate)

when I call that method like this below:

   AddNewRowToTable(....,"2008/04/14")

It said it can't convert string to DateTime.

help!

3
  • 1
    try New DateTime(year, month, day) instead of 2008/04/14 Commented Jul 15, 2013 at 2:56
  • 1
    what is AddNewRow? can you update the question with code? Commented Jul 15, 2013 at 2:56
  • 1
    AddNewRow and AddNewRowToTable are not the same. Correct the question please. Also you can not pass a different type unless some kind of function overloading is implemented by you for your function. Commented Jul 15, 2013 at 2:58

4 Answers 4

7
You have to do AddNewRow(....,new DateTime(..))

or AddNewRow(....,DateTime.ParseExact(dateString, format, provider))

There is no implicit conversion from string

Sign up to request clarification or add additional context in comments.

Comments

4

You will have to convert the string to type DateTime. You can convert it in this way:

AddNewRow(....,new DateTime.ParseExact("2009-05-08", "yyyy-MM-dd",
                                       System.Globalization.CultureInfo.InvariantCulture))

Comments

0

You need to pass correct type for the input parameter. Look into function overloading if you want to pass a String and then convert it into DateTime inside the function.

Comments

0

To add a little to the previous answers new DateTime() it appears to expect a long.

So it has to be divided by "," as such:

AddNewRowToTable(....,new DateTime(2008,04,14))

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.