Solved

Problem comparing dates at midnight

Posted on 2014-12-29
2
94 Views
Last Modified: 2014-12-29
I have two dates, both at midnight
e.g. 06/06/2014 and 12/29/2014
Both dates are exactly midnight (at least they should be), they are in datetime format and show no time section
I am using adddays to add 1 day each time in a loop until the
1st date = 2nd date
Problem is that even though on debug the dates eventually look equal, they are never equal and the loop continues.
I have also compared them in an if statement and they are not equal but they look the same.
Any help most welcome.
0
Comment
Question by:SweetingA
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 40522356
How do you display the dates?

The "look" is dependent on the format used for the diplay. If the time is not specifically requested, then it might not display.

Try the following in your loop and then look at result in the Output window. You can activate it from the Debug menu if it is not visible:

Debug.WriteLine(String.Format("{0:MM/dd/yyyy hh:mm:ss}", FirstDate) & " --- " & String.Format("{0:MM/dd/yyyy hh:mm:ss}", SecondDate) & " --- " & FirstDate.Millisecond & " --- " & SecondDate.Millisecond)

Open in new window


The first 2 values will show you if there is a time recorded, and the last 2 if there are milliseconds recorded in the date. These never display by default, but they can make the difference.
0
 

Author Comment

by:SweetingA
ID: 40522377
Acrually the output did not display (unsure why) but the answer was clear - some millseconds in the 2nd date

Thanks a lot
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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
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…
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…

820 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