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

  • Home
  • SEARCH
  • 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 6082815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:19:52+00:00 2026-05-23T11:19:52+00:00

I have an instance of DateTime that I get from my database, I want

  • 0

I have an instance of DateTime that I get from my database, I want to subtract it from DateTime.Now and find out if 4 hours were passed. How do I do that?

Also when should i use DateTime.UTCNow or DateTimeOffset

  • 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-23T11:19:53+00:00Added an answer on May 23, 2026 at 11:19 am

    You can use the subtraction operator to get a TimeSpan:

    private static readonly TimeSpan MinimumTime = TimeSpan.FromHours(4);
    
    ...
    
    if ((dateFromDatabase - DateTime.Now) > MinimumTime)
    {
        ...
    }
    

    As for whether you need UTCNow or Now… it will depend on what happens to time zones when you fetch the data from the database. DateTime is not terribly clear on this front 🙁

    If you can fetch the value as a DateTimeOffset to start with, then you can use DateTimeOffset.Now instead and it should be simpler to work out any time zone issues.

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

Sidebar

Related Questions

I have an instance of Class A that I want to refer to in
I have a JodaTime Period that I've created from two DateTime instants. Is there
I have a function that looks like this: def getCurrentShow(hour=(localtime().tm_hour),day=datetime.datetime.now().strftime('%A')): return Schedule.objects.get(hour=hour,day=day).show so I
I have an instance of a UITableView, and a separate class that adheres to
I have an instance of Apache Tomcat 6.x running, and I want it to
If I have an instance of a System.Timers.Timer that has a long interval -
I have a model for a User generated by EF from an existing database:
I have a problem with a plone-instance. On startup i get this CRITICAL Message
I have a legacy SQL Server 2000 database that has one column that has
I have the following interfaces defined: public interface IAudit { DateTime DateCreated { get;

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.