web analytics

how to change datetime in a C# debug session?

Options

codeling 1606 - 6684
@2026-07-06 11:02:10

To change a DateTime value while debugging in Visual Studio, you must reassign the variable using a new DateTime constructor or a parse method, because individual DateTime properties like Year or Hour are strictly immutable.

You can accomplish this using DataTips, the Watch Window, or the Immediate / Debug Console.

 

1. Using DataTips (Hover) or the Locals/Watch Window
  1. Hit a breakpoint to pause execution.
  2. Hover over your DateTime variable to open the DataTip, or find it in the Locals or Watch Window.
  3. Click directly on the value column to make it editable.
  4. Clear the existing text and type an instantiation statement:

    csharp

    new DateTime(2026, 12, 25, 14, 30, 0)
    

    Use code with caution.

  5. Press Enter to apply the change. 

 

2. Using the Immediate Window or Debug Console

If you prefer a command-line style interface to change values: 

  1. Open the window via Debug > Windows > Immediate (or Debug Console in VS Code).
  2. Directly assign a parsed string or a new instance to your variable:

    csharp

    myDateVariable = DateTime.Parse("2026-07-06 13:45:00")
    

    Use code with caution.

  3. Press Enter, and the variable will retain this value for the remainder of your debugging session. 

Comments

You must Sign In to comment on this topic.


© 2026 Digcode.com