String as Datetime

  • Thread starter Thread starter Guest
  • Start date Start date
msnews.microsoft.com said:
Hello.
How can I specify datetime by string?
In VB.NET I can write by "#" simbol like this: #10/12/2004 12:00#.
How can I do it in C#?


Try this:

string theTime = "10/12/2004 12:00";
DateTime dt_theTime = DateTime.Parse(time);

Hopfully it works well.


Greetings


Sergej
 
Hello.
How can I specify datetime by string?
In VB.NET I can write by "#" simbol like this: #10/12/2004 12:00#.
How can I do it in C#?
 
check this it should be work
in C#
string strdatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.sss");
 
I don't think that what you want to do is possible. I don't believe
there is a syntax for representing a date time as a string in code. You
will have to create a string, and then actually execute code to change it
into a DateTime, as others have indicated.

Hope this helps.
 
Back
Top