Solved

DateTime.Equal returns false when true?

Posted on 2013-05-31
4
351 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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