Solved

DateTime.Equal returns false when true?

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

733 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