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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:53:03+00:00 2026-06-08T06:53:03+00:00

I have this simple program: DateTime aux = new DateTime(2012, 6, 12, 12, 24,

  • 0

I have this simple program:

        DateTime aux = new DateTime(2012, 6, 12, 12, 24, 0);
        DateTime aux2 = new DateTime(2012, 6, 12, 13, 24, 0);
        aux2.AddDays(1);

       Console.WriteLine((aux2 - aux).TotalHours.ToString());

        Console.ReadLine();

I debugged this and found aux2.AddDays(1); doesn’t seem to work, what am I missing here?
it should return 25 but the answer is one.

What is the problem?

also AddHours doesn’t work, I guess that the others aren’t working too.

  • 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-08T06:53:05+00:00Added an answer on June 8, 2026 at 6:53 am

    It does work but you don’t do anything with the return value, try

    aux2 = aux2.AddDays(1);
    

    DateTimes share this facet of immutability with Strings.


    EDIT

    There is a little paragraph about it on MSDN

    This method does not change the value of this DateTime. Instead, it
    returns a new DateTime whose value is the result of this operation.

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

Sidebar

Related Questions

My situation is simple. I have this in my program: File folder = new
I have this simple program that computes salaries for four different worker types. It's
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I have this simple c++ program #include <cstdlib> #include <iostream> #include <math.h> #include <stdlib.h>
I have this following simple program: int main() { char* v = getenv(TEST_VAR); cout
I have this simple little batch file program that I wrote but it fails
I have this following simple service program: using System.Diagnostics; using System.ServiceProcess; namespace BasicService {
I have this simple program #include <stdio.h> int main(void) { unsigned int a =
I have this simple program using powershell. This is just a proof of concept,

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.