Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3227532
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:35:09+00:00 2026-05-17T16:35:09+00:00

I wonder how to compare two DateTime objects in .NET using DateTime methods Compare

  • 0

I wonder how to compare two DateTime objects in .NET using DateTime methods Compare, CompareTo or Equals without comparing ticks.

I only need a tolerance level of milliseconds or seconds.

How can this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T16:35:09+00:00Added an answer on May 17, 2026 at 4:35 pm

    You can subtract one DateTime from another to produce a TimeSpan that represents the time-difference between them. You can then test if the absolute value of this span is within your desired tolerance.

    bool dtsWithinASecOfEachOther = d1.Subtract(d2).Duration() <= TimeSpan.FromSeconds(1);
    

    The call to TimeSpan.Duration() can be omitted if you know that the first DateTime cannot represent an earlier point in time than the other, i.e. d1 >= d2.

    To answer your query about the comparison methods,
    DateTime.Compare(d1, d2) produces the same result as d1.CompareTo(d2):

    • 0 if they represent the same point in time (d1.Equals(d2) , d1 == d2). Do note though, that the resolution of DateTime is 1 tick = 100 nanoseconds = 10 ^ -7 seconds.
    • A value greater than 0 if d1 is chronologically after d2 (d1 > d2)
    • A value less than 0 if d1 is chronologically before d2 (d1 < d2)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to compare the integer part of two doubles for inequality and I'm
I use SVN as the source control system, and I wonder how to compare
I wonder if there is a way to either programatically or using a third
I wonder if there is an easy way to check if two strings match
I wonder how weak references work internally, for example in .NET or in Java.
If I override Equals and GetHashCode, how do I decide which fields to compare?
Wonder what the difference between: static PROCESSWALK pProcess32First=(PROCESSWALK)GetProcAddress(hKernel,Process32First); ... pProcess32First(...); what is hKernel? Look
I wonder if someone knows if there is a pre-made solution for this: I
I wonder how you guys manage deployment of a database between 2 SQL Servers,
I wonder if anyone uses commercial/free java obfuscators on his own commercial product. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.