Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass DateTime value parameter?

Tags:

c#

datetime

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!

like image 562
deva Avatar asked Dec 26 '22 00:12

deva


2 Answers

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

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

There is no implicit conversion from string

like image 116
TGH Avatar answered Jan 16 '23 18:01

TGH


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))
like image 43
Shaharyar Avatar answered Jan 16 '23 19:01

Shaharyar