Solved

DateTime.Equal returns false when true?

Posted on 2013-05-31
4
349 Views
Last Modified: 2013-06-03
Code below is returning FALSE when I'd expect TRUE as comparing the SAME Dates.

Please advise

CODE
Debug.Print(Timestamp.ToString)
Debug.Print(Timestamp2.ToString)
Dim dateEqual = DateTime.Equals(Timestamp, Timestamp2)
Debug.Print(dateEqual)

OUTPUT from console
31/05/2013 16:56:19
31/05/2013 16:56:19
False
0
Comment
Question by:rwallacej
  • 2
4 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 39211226
maybe its including milliseconds?
0
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 100 total points
ID: 39211247
seems that method relies on the Ticks property of the DateTime object.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 400 total points
ID: 39211319
If you want to know if the dates are equal, ignoring the time portion, then:
        Dim dateEqual = DateTime.Equals(Timestamp.Date, Timestamp2.Date)

Open in new window


Or, if you want to truncate the milliseconds portions, then compare:
*From Joe over at stackoverflow.
        Dim Timestamp As DateTime = DateTime.Now
        Dim Timestamp2 As DateTime = DateTime.Now

        Timestamp = Timestamp.AddTicks(-(Timestamp.Ticks Mod TimeSpan.TicksPerSecond))
        Timestamp2 = Timestamp2.AddTicks(-(Timestamp2.Ticks Mod TimeSpan.TicksPerSecond))

        Debug.Print(Timestamp.ToString)
        Debug.Print(Timestamp2.ToString)
        Dim dateEqual = DateTime.Equals(Timestamp.Date, Timestamp2.Date)
        Debug.Print(dateEqual)

Open in new window

0
 

Author Closing Comment

by:rwallacej
ID: 39215882
thanks for help
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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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 is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

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

19 Experts available now in Live!

Get 1:1 Help Now