5

If I place a breakpoint and cause code execution to pause on a line where I wish to test the value of a DateTime variable, the Visual Studio 2013 debugger will display the value of my DateTime variable in the form "{10/1/2017 12:00:00 AM}" when I hover it and even allow me to begin to edit it--but when I press Enter I get the error, "Invalid expression term '{'". What is the proper way to edit a DateTime variable on the fly during a debug session?

3 Answers 3

13

While execution is paused, a little datatip pop-up appears when you hover over your DateTime variable. Click the date within to begin editing it. Switch the squiggly parentheses to quotes, and surround the entire quoted date with a call to DateTime.Parse, like so:

DateTime.Parse("10/1/2017 12:00:00 AM")

You can then change the date inside the quote to whatever new date you want--and when you press Enter, the corresponding DateTime value will be inserted into your variable on the fly!

2
  • Thanks for sharing your solution here, since it has been resolved, please mark it as the answer later, so it could help other community members who get the same issue, Have a nice day:)
    – Jack Zhai
    Sep 14, 2017 at 1:42
  • Ended up here when searching how to change Guids, and this is the exact same solution. Just do Guid.Parse("NEW_GUID")
    – Déjà vu
    Jul 27, 2022 at 9:38
0

Perhaps, this could help:

How do I enter a DateTime value in the VS QuickWatch window?

This post says that is's immutable: https://stackoverflow.com/a/489741/267000

Another way to edit it at runtime is Open Immediate Window: Debug -> Windows -> Immediate and edit with usual in C# syntax

0

Where the DateTime is a property of another object, it's possible to set the value using the Immediate Window. In the example command is a generic type parameter passed to a method so needs to be cast to the correct type before the property is accessible:

(command as SomeCommandWithDateTimeProp).ToDate = System.DateTime.Parse("2021-10-12")

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.