Cast string to DateTime

G

Guest

I have an object string property that is a string. I want to convert to a
DateTime. Any ideas?

DateTime eventDt = ((DateTime)mEvent.EventDt).Date;

Error 1 Cannot convert type 'string' to 'System.DateTime'
 
M

Mark Rae

I have an object string property that is a string. I want to convert to a
DateTime. Any ideas?

DateTime eventDt = ((DateTime)mEvent.EventDt).Date;

Error 1 Cannot convert type 'string' to 'System.DateTime'

You need to use the Parse or ParseExact methods of the DateTime object.

string strTest = "25 May 2006";
DateTime dtmTest = DateTime.Parse(strTest);
 
B

Barry Kelly

mgonzales3 said:
I have an object string property that is a string. I want to convert to a
DateTime. Any ideas?

DateTime eventDt = ((DateTime)mEvent.EventDt).Date;

Error 1 Cannot convert type 'string' to 'System.DateTime'

DateTime.Parse()

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top