dotnet / dotnet/efcore

Translate DateTime subtraction with TimeSpan member access via DATEDIFF

Open
#31,135 0 comments 3 reactions 0 assignees View on GitHub
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

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.