Solved

DateTime.Equal returns false when true?

Posted on 2013-05-31
4
348 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
Comment Utility
maybe its including milliseconds?
0
 
LVL 22

Assisted Solution

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

Accepted Solution

by:
Mike Tomlinson earned 400 total points
Comment Utility
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
Comment Utility
thanks for help
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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

14 Experts available now in Live!

Get 1:1 Help Now