473,385 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Turning a datetime object to string

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'

Nov 17 '05 #1
4 15031
The output of ToString() is a string, so you have to save it in a string
variable.

string mystring = mydateobject.ToString();

"Chumley Walrus" <sp*******@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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'

Nov 17 '05 #2
"Chumley Walrus" <sp*******@yahoo.com> a écrit dans le message de news:
11*********************@f14g2000cwb.googlegroups.c om...
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

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #3
You would need a string to assign to:
string sDateTime = DateTime.Now.ToString()
or in your case:
string sDateTime = mydateobject.ToString()

"Chumley Walrus" <sp*******@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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'

Nov 17 '05 #4
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


"Chumley Walrus" wrote:
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'

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Symon R | last post by:
This is a bit of a weird one that I haven't yet been able to solve - I'm hoping someone out there can disprove my findings and tell me where I've gone wrong! I have designed a web service that...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
2
by: andrew lowe | last post by:
Hi, Please bear with me on this problem, first I'll give you some background: I have an object that contains a DateTime field which i pass to a webservice public class Foo { public DateTime...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
5
by: I am Sam | last post by:
I have created this DateTime object and instanced it I think correctly DateTime myClubNow1=new...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
11
by: Tim | last post by:
Hi, I am trying to do something simple. Convert a string date to datetime but it is not working and is giving me a baffling error! System.Convert.ToDateTime("Jan 30, 2006")...
5
by: js | last post by:
I have a textbox contains text in the format of "yyyy/MM/dd hh:mm:ss". I need to parse the text using System.DateTime.Parse() function with custom format. I got an error using the following code. ...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.