Skip to content

SQL Server Query: DateTime addition/subtraction translation to server #11039

Description

@smitpatel

Addition/subtraction of DateTime gives type of TimeSpan. At present postgre can do it correctly because it has mapping type - interval.

This issue is to track,

  • Translation of addition/subtraction for DateTime to server and materializing it back to TimeSpan on client side doing some computation.
  • Translation of member access on +/- of DateTime (e.g. (DateTime - DateTime).TotalDays) to server. For SQLite it may be possible to do using julianday function subtraction which gives difference of days in REAL type. Reading a TimeSpan will coerce the REAL value.

Activity

  1. added this to the Backlog milestone on Feb 28, 2018
  2. bricelam commented on Apr 25, 2018

    @bricelam
    Contributor

    We can't translate this on SQLite (without registering a UDF). If we rely on coercion, queries like this would fail:

    var tickesOverSLA
        = from t in tickets
          where DateTime.Now - t.DateOpened > t.SLA
          select t;
  3. changed the title [-]Query: DateTime addition/subtraction translation to server[/-] [+]SQL Server Query: DateTime addition/subtraction translation to server[/+] on Apr 25, 2018
  4. NetMage commented on May 13, 2020

    @NetMage

    @bricelam Why won't the SQLite date and strftime functions work to translate the query?

  5. bricelam commented on May 13, 2020

    @bricelam
    Contributor

    @NetMage They work just fine. (see PR #19617)

    My comment was more that if we did this by default for all relational providers, the results would be wrong for SQLite.

  6. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions