VB - format datetime

How do I format this datetime:

      9/9/2010 12:00:00 AM

To:

      2010-09-09 12:00:00.000

LVL 13
RickAsked:
Who is Participating?
 
vusovConnect With a Mentor Commented:
Please try this Convert.ToDateTime("9/9/2010 12:00:00 AM").ToString("yyyy-MM-dd hh:mm:ss.fff")
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Dim dt As Date = "9/9/2010 12:00:00"
        Me.TextBox1.Text = dt.ToString("yyyy-MM-dd HH:mm.ss")
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
sorry
Dim dt As Date = "9/9/2010 12:00:00"
        Me.TextBox1.Text = dt.ToString("yyyy-MM-dd HH:mm:ss.ms")
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
RickAuthor Commented:
That gives me 2010-09-09 00:00:00.00
How do I show the milliseconds with 3 digits?
0
 
Dave BaldwinFixer of ProblemsCommented:
On this page: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm  is a listing of DateTime.ToString() formats.

DateTime.ToString ( 'u' ) is close but more detailed versions are listed.

Note that 9/9/2010 12:00:00 AM will become 2010-09-09 00:00:00.000 in 24-hour time.
0
 
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
Dim dt As Date = "9/9/2010 12:00:00"
        Me.TextBox1.Text = dt.ToString("yyyy-MM-dd HH:mm:ss.fff")
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
See: http://msdn.microsoft.com/en-us/library/8kb3ddd4(VS.80).aspx

You should be able to use "fff" for the milliseconds so "HH:mm:ss.fff" for the time portion.
0
 
RickAuthor Commented:
Thank you! That works.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.