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 8428253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:00:08+00:00 2026-06-10T05:00:08+00:00

I want to have the difference of two DateTimeOffset object in days( for example

  • 0

I want to have the difference of two DateTimeOffset object in days( for example check if the difference is less than 40 days).

I know it can be done by change it to FileTime, but wondering if there is any better way of doing it.

  • 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-06-10T05:00:09+00:00Added an answer on June 10, 2026 at 5:00 am

    The easiest way would be to subtract the offsets from eachother. It returns a TimeSpan you can compare to.

    var timespan = DateTimeOffset1 - DateTimeOffset2;
    // timespan < TimeSpan.FromDays(40);
    // timespan.Days < 40
    

    I tend to prefer the ability to add it to another method passing in a TimeSpan, so then you’re not limited to days or minutes, but just a span of time. Something like:

    bool IsLaterThan(DateTimeOffset first, DateTimeOffset second, TimeSpan diff){}
    

    For fun, if you love fluent style code (I’m not a huge fan outside of it outside of testing and configuration)

    public static class TimeExtensions
    {
        public static TimeSpan To(this DateTimeOffset first, DateTimeOffset second)
        { 
            return first - second;
        }
    
        public static bool IsShorterThan(this TimeSpan timeSpan, TimeSpan amount)
        {
            return timeSpan > amount;
        }
    
        public static bool IsLongerThan(this TimeSpan timeSpan, TimeSpan amount)
        {
            return timeSpan < amount;
        }
    }
    

    Would allow something like:

    var startDate = DateTimeOffset.Parse("08/12/2012 12:00:00");
    var now = DateTimeOffset.UtcNow;
    
    if (startDate.To(now).IsShorterThan(TimeSpan.FromDays(40)))
    {
        Console.WriteLine("Yes");
    }
    

    Which reads something like “If the time from start date to now is shorter than 40 days”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following two arrays. I want the difference between these two arrays. That
How can I get the set difference of two result sets? Say I have
i want to know the time difference between two countries. There is ofcourse the
I have two NSDate objects and I want the difference between the two and
I want to have summary of difference between two files. Expected output is count
I have two linux timestamps begine-time and expire-time, i want to take difference between
I have two different buttons on my page. I want them both to be
I want to have a MKMapView with an two different overlays. First, I have
I have two different arrays, one with strings and another with ints. I want
I have two sites with different SITE_IDs, but I want to have only one

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.