Solved

VB - format datetime

Posted on 2010-09-09
8
379 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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