Dates are immutable objects, i.e. they cannot be modified after creation. DateTime.AddHours returns a new DateTime instance which is shifted backwards by 4 hours but “date” will not be modified.
Use:
DateTime newDate = date.AddHours(-4);
More Related Contents:
- How do I calculate someone’s age based on a DateTime type birthday?
- DateTime vs DateTimeOffset
- Parse DateTime with time zone of form PST/CEST/UTC/etc
- String was not recognized as a valid DateTime ” format dd/MM/yyyy”
- Algorithm to detect overlapping periods [duplicate]
- C# DateTime.Now precision
- How to get difference between two dates in Year/Month/Week/Day?
- format date in c#
- How do I get the last day of a month?
- What does “DateTime?” mean in C#?
- Measuring code execution time
- Get Month name from month number
- Environment.TickCount vs DateTime.Now
- How do I represent a time only value in .NET?
- Parse C# string to DateTime
- DateTime ToString issue with formatting months with “mm” specifier
- How do I get the AM/PM value from a DateTime?
- How to ensure a timestamp is always unique?
- How can I format DateTime to web UTC format?
- How frequent is DateTime.Now updated ? or is there a more precise API to get the current time?
- Convert String to Date in .NET if my incoming date format is in YYYYMMDD
- How to parse and generate DateTime objects in ISO 8601 format
- DateTime conversion from string C#
- DateTime.Parse(“2012-09-30T23:00:00.0000000Z”) always converts to DateTimeKind.Local
- Getting the first and last day of a month, using a given DateTime object
- Days, hours, minutes, seconds between two dates
- How to check if a DateTime occurs today?
- Convert DateTime to long and also the other way around
- Convert Date from Persian to Gregorian
- .NET DateTime to SqlDateTime Conversion