Solved

VB - format datetime

Posted on 2010-09-09
8
370 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
Comment Utility
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
Comment Utility
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
Comment Utility
That gives me 2010-09-09 00:00:00.00
How do I show the milliseconds with 3 digits?
0
 
LVL 3

Accepted Solution

by:
vusov earned 500 total points
Comment Utility
Please try this Convert.ToDateTime("9/9/2010 12:00:00 AM").ToString("yyyy-MM-dd hh:mm:ss.fff")
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you! That works.

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now