Solved

can't milliseconds to datetime in console app

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

24 Experts available now in Live!

Get 1:1 Help Now