• RV
    • Missy – My Home
    • JBAM – Newmar Dutch Star
    • Shaneeda
    • Buying a Used RV
    • Gas vs Diesel RVs
    • Ideal Motorhome
    • Choosing the Ideal RV
  • Cycling
  • Jeep
  • About
  • Flying
    • Vans RV-4
    • Daisy – RV-3B
  • Resources
  • Subscribe

JdFinley.com

Fulltime RV Living Adventures

  • Is Solar For You?
  • Gas vs Diesel RVs
  • Buying a Used RV
  • Choosing the Ideal RV
  • Ideal Motorhome

Compare Date Values

June 17, 2011

ASP VB C# .Net Microsoft Framework Web Site Tip compreI see a lot of code that requires one to compare two date, date and time, or time only values.  I think there may be as many ways to skin this cat as there are developers given the number of examples I’ve seen.  This I know, the proper way to compare date (or datetime) data types in .Net is to use Date.Compare like so:

DateTime.Compare(_date1, _date2) > 0

The result is documented on MSDN which states:

Less than zero = first date is earlier than the second.
Zero = first date is the same as the second.
Greater than zero = first date is later than the second.

The thing that seems to catch some guys is that the above works just fine with Date or DateTime data types that only contain hours, minutes, seconds such as the following variable:

_currentTime As DateTime = String.Format("{0}:{1}", Now.Hour, Now.Minute)

Of course, there is no year, month, day resolution in using a variable value such as this. A comparison can only tell you how the HH:MM:SS value of one variable compares to another.

(Visited 109 times, 1 visits today)

Related posts:

No related posts.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You know what the first rule of sailing is? …Love. You can learn all the math in the ‘verse, but you take a boat to the sea you don’t love, she’ll shake you off just as sure as the turning of the worlds. Love keeps her going when she oughta fall down, tells you she’s hurting ‘fore she keens. Makes her a home.

— Capt. Malcolm Reynolds (Serenity)

Popular Posts

  • Powermatic Model 90 Wood Lathe & VFD
  • Wood Turning on a Lathe
  • Chainsaw Review: Sportsman 20 in. 52cc
  • Cielo Grande Barbed Wire Fence Repair

Email Notification


 

Posts by Subject

3DPrinting Aircraft Airstrip Bible Bus bus boys Camping Cat Computers Cycling Development Electrical electronics Entertainment Environment Factory Five family FAQ Finances flying Food God Health Holiday Home Humor kayak Life Maintenance Nature Photography Review RV-3 RV-4 sailboat sailing self improvement Sewing solar Travel Video weather wood woodworking X-Country

Posts by Month

© Copyright © 2025 JDFinley.com · All Rights Reserved · Privacy Policy

Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to JD Finley and JdFinley.com with appropriate and specific direction to the original content.