Solved

Problem comparing dates at midnight

Posted on 2014-12-29
2
91 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

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

12 Experts available now in Live!

Get 1:1 Help Now