Solved

VB - format datetime

Posted on 2010-09-09
8
382 Views
Last Modified: 2013-11-27
How do I format this datetime:

      9/9/2010 12:00:00 AM

To:

      2010-09-09 12:00:00.000

0
Comment
Question by:Rick
8 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33639110
Dim dt As Date = "9/9/2010 12:00:00"
        Me.TextBox1.Text = dt.ToString("yyyy-MM-dd HH:mm.ss")
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33639120
sorry
Dim dt As Date = "9/9/2010 12:00:00"
        Me.TextBox1.Text = dt.ToString("yyyy-MM-dd HH:mm:ss.ms")
0
 
LVL 13

Author Comment

by:Rick
ID: 33639140
That gives me 2010-09-09 00:00:00.00
How do I show the milliseconds with 3 digits?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 3

Accepted Solution

by:
vusov earned 500 total points
ID: 33639147
Please try this Convert.ToDateTime("9/9/2010 12:00:00 AM").ToString("yyyy-MM-dd hh:mm:ss.fff")
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33639151
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
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33639161
Dim dt As Date = "9/9/2010 12:00:00"
        Me.TextBox1.Text = dt.ToString("yyyy-MM-dd HH:mm:ss.fff")
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33639170
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
 
LVL 13

Author Closing Comment

by:Rick
ID: 33639183
Thank you! That works.

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question