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.
 

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

Similar Threads

XML 1
NTFS Folder Permissions 4
own executalbe path 7
enum types 4
Equals(String, String, StringComparison) ? 1
Hashtable.Item 2
Trim not working 3
Hex with .ToString("X") 1

Back
Top