Solved

can't milliseconds to datetime in console app

Posted on 2014-02-11
2
195 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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

11 Experts available now in Live!

Get 1:1 Help Now