dotnet / dotnet/dotnet-api-docs

DateTimeOffset.Subtraction Remarks Example Contains Minor Discrepancy

Open
#9,537 0 comments 0 reactions 0 assignees View on GitHub
area-System.DateTime Pri3
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/DateTimeOffsetSubtraction-Remarks-Examp/10552416)._

---
[severity:It bothers me. A fix would be nice]
[DateTimeOffset.Subtraction](https://learn.microsoft.com/en-us/dotnet/api/system.datetimeoffset.op_subtraction?view=net-8.0#system-datetimeoffset-op-subtraction(system-datetimeoffset-system-datetimeoffset)) Remarks section example has a minor discrepancy.

Original
```
difference = firstDate - thirdDate;
Console.WriteLine("({0}) - ({1}): {2} days, {3}:{4:d2}",
firstDate.ToString(),
secondDate.ToString(),
difference.Days,
difference.Hours,
difference.Minutes);
// The example produces the following output:
// (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 0 days, 2:00
// (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 26 days, 9:00
```
When calculating the difference the second time, the output uses **secondDate** where it should use **thirdDate**.

Updated

```
difference = firstDate - thirdDate;
Console.WriteLine("({0}) - ({1}): {2} days, {3}:{4:d2}",
firstDate.ToString(),
thirdDate.ToString(),
difference.Days,
difference.Hours,
difference.Minutes);
// The example produces the following output:
// (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 0 days, 2:00
// (3/25/2008 6:00:00 PM -07:00) - (2/28/2008 9:00:00 PM -07:00): 26 days, 9:00
```

---
### Original Comments

#### Feedback Bot on 1/3/2024, 05:51 PM:

(private comment, text removed)

---
### Original Solutions
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.