Solved

can't milliseconds to datetime in console app

Posted on 2014-02-11
2
200 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net datagrid point 4 35
Web page design problem 3 42
Office 365: Assigning MailboxPlan to a mailbox 8 72
XML and Linq - reading fields in repeating nodes 3 26
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…
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…

710 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