Turning a datetime object to string

C

Chumley Walrus

This may be easier than I think, but I need to find a quick way to
change a datetime object to string, as the following

mydateobject = mydateobject.ToString();

renders the error: Cannot implicitly convert type 'string' to
'System.DateTime'
 
J

Joanna Carter \(TeamB\)

This may be easier than I think, but I need to find a quick way to
change a datetime object to string, as the following

mydateobject = mydateobject.ToString();

renders the error: Cannot implicitly convert type 'string' to
'System.DateTime'

You are getting the string representation of a date and then trying to
assign it back to the date variable.

try :

string dateAsString = myDateObject.ToString();

Joanna
 
P

Peter Rilling

The output of ToString() is a string, so you have to save it in a string
variable.

string mystring = mydateobject.ToString();
 
M

Mark White

You would need a string to assign to:
string sDateTime = DateTime.Now.ToString()
or in your case:
string sDateTime = mydateobject.ToString()
 
G

Guest

Hi Chumley,
you are trying to assign a string to a DateTime object, your mydateobject
is of type DateTime, how about this instead:

DateTime d = DateTime.Now;
string dateString = d.ToString();

Hope that helps
Mark R Dawson
http://www.markdawson.org
 

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