Solved

can't milliseconds to datetime in console app

Posted on 2014-02-11
2
199 Views
Last Modified: 2014-02-11
I simply loop thru the following and try to increment my date by 1 ms. This functionality is in a dll that gets instantiated in my main app. It never increments. Any ideas?

dim m_datEntryDate as datetime=now

m_datEntryDate = m_datEntryDate.AddMilliseconds(1)
0
Comment
Question by:glenn_r
2 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 200 total points
ID: 39851698
I tried this... it does increment the date/time... but I'm guessing that you are not formatting the date in order to be able to see the milliseconds.

With the following code:
Module Module1

    Sub Main()
        Dim m_datEntryDate As DateTime = Now
        Dim dateFormat As String = "MM/dd/yyyy hh:mm:ss.fffffff"

        Console.WriteLine("Original date: {0} ({1:N0} ticks)", m_datEntryDate.ToString(dateFormat), m_datEntryDate.Ticks)
        Console.WriteLine()

        m_datEntryDate = m_datEntryDate.AddMilliseconds(1)

        Console.WriteLine("New date: {0} ({1:N0} ticks)", m_datEntryDate.ToString(dateFormat), m_datEntryDate.Ticks)
        Console.WriteLine()

    End Sub

End Module

Open in new window


I got the following output:

Original date: 02/11/2014 04:17:34.1060154 (635,277,322,541,060,154 ticks)

New date: 02/11/2014 04:17:34.1070154 (635,277,322,541,070,154 ticks)

Note that the number of ticks increased by 10,000.  (1 ms = 10,000 ticks)
0
 

Author Comment

by:glenn_r
ID: 39851776
I was displaying the ms
I solved the problem but don't know why
might have something to do with the datetime object being immutable
as mentioned my calling app instantiates a dll containing this functionality
originally had the logic coupled in a for loop with allot of other code
it didn't work in that context
i created an object level variable and added a function that incremented the date and it worked
thanks for the backup
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 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