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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:37:21+00:00 2026-06-10T02:37:21+00:00

If I try: DateTime.Now.Subtract(DateTime.UtcNow) I would expect the result to be very close to

  • 0

If I try:

DateTime.Now.Subtract(DateTime.UtcNow)

I would expect the result to be very close to zero. But it’s not, instead it’s the time zone difference, in my case, -4 hours. There is a .Kind — the DateTime KNOWS the timezones are different. Why doesn’t it track this for me? Is there a flavor of Subtract that DOES use Kind correctly?

(For reference, a good rundown of what each one outputs can be seen at: https://stackoverflow.com/a/3229429/237091)

  • 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-10T02:37:23+00:00Added an answer on June 10, 2026 at 2:37 am

    There is a .Kind — the DateTime KNOWS the timezones are different. Why doesn’t it track this for me?

    Because DateTime is fundamentally broken (and there’s more…). IMO it should complain if you try to subtract a value of one kind from another. But no, it just uses the uninterpreted date/time in each value. Very few operations actually take any notice of the Kind, unfortunately. (If you use TimeZoneInfo, those operations do take notice of it.)

    Kind was hacked into .NET 2.0; before then a DateTime value didn’t even know what kind it was – if you used:

    dt = dt.ToLocalTime().ToLocalTime().ToLocalTime();
    

    it would apply the same offset change several times. The BCL team found a couple of spare bits in the binary representation, and used it for Kind.

    Basically, I feel your pain. Personally I would prefer it if operations like this threw an exception – subtracting a UTC DateTime from a local DateTime or vice versa makes little sense, IMO.

    As an entirely biased plug, you could use Noda Time which separates the ideas of Instant, LocalDate, LocalTime, LocalDateTime, OffsetDateTime and ZonedDateTime, and doesn’t let you perform non-sensical arithmetic. Our aim is to provide a saner API than the BCL one. That doesn’t necessarily mean we’ve succeeded, of course 🙂

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

Sidebar

Related Questions

try: c = db.cursor() c.execute(insert or replace into registrations values + (?, ?, datetime('now')),
I am stuck with this problems for a long time now. Everything I try
I store some DateTime in a CSV log with: DateTime.Now.ToString(MM/dd/yyyy hh:mm:ss.fff) When I try
I try to compare Datetime.Now with a Datetime variable I set, using the Datetime.CompareTo()
I will try everything but not working this( dd/MM/yyyy ) date format, this always
This code has been working for a long time now but has broken now
Till today I am using DateTime.Now; function to save the time and data of
This is main program.cs LogError.WriteError(Application started: + DateTime.Now + Environment.NewLine); try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false);
In ASP.NET Web Forms,i would accomplish that easily: [...] try { DateTime date =
I have the following code DateTime now = DateTime.UtcNow; var allItemsOver64 = _inventoryContext.Items.Where(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.