string strDateTime = sampledate; (when i use this "it shows Cannot implicitly convert type system.DateTime ? to String)
DateTime myDateTime = DateTime.Parse(strDateTime );
Please some one guide me what is the right way to convert
C#
Last Comment
Sha1395
8/22/2022 - Mon
Paul Jackson
The error you say you're getting with option 2 implies that sampledate is already in system.datetime format
Sha1395
ASKER
even i thought the same but when i pass the value as it is to DB,i gotta an error can't convert type from string to DateTime.
Paul Jackson
What code are you using to pass to the database
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Dmitry G
I believe you problem is simple.
string strDateTime = sampledate;
The sampledate variable is a DateTime variable, I believe, not a string. Therefore you need to convert it to string. E.g.,
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
Here is the below value am getting "dateToSave = {23/03/1992 12:00:00 AM}" but when it pass it to DB am getting error "Error Converting data type Char to datetime"