Translate DateTime subtraction with TimeSpan member access via DATEDIFF
Open
area-query
area-sqlserver
customer-reported
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
For getting e.g. the number of days between two timestamps, one must currently use the SQL Server-specific DATEDIFF function - this isn't very discoverable and also makes the query SQL Server-specific.
We could instead pattern match and identify .NET DateTime subtraction which is immediately followed by a member access on the resulting TimeSpan: `(b.DateTime - new DateTime(2020, 1, 1)).Days`; we'd then translate that to DATEDIFF under the hood, allowing simple C# syntax which would also be compatible with other providers.
See e.g. #31132 where this was discussed.
Contributor guide
Assessment
This issue has not been assessed yet.