Solved

can't milliseconds to datetime in console app

Posted on 2014-02-11
2
197 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

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

Suggested Solutions

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

823 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