Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: DateDiff Function #1837

Open
rmocode opened this issue Feb 2, 2024 · 2 comments · Fixed by #1876
Open

Feature Request: DateDiff Function #1837

rmocode opened this issue Feb 2, 2024 · 2 comments · Fixed by #1876
Assignees

Comments

@rmocode
Copy link

rmocode commented Feb 2, 2024

Hello,

The MySQLDbFunctionsExtensions class has support for many of the specific date difference operations that MySql supports through its function TIMESTAMPDIFF(TIME_UNIT, startDate,endDate), but it doesn't support all of them. For example, there is no support for using QUARTER as a time metric, which you can do in MySql. Of course, the result for MONTH can be divided by 3, as a workaround, which is fine, but there is another issue:

There is no way to write one LINQ Query that takes a unit of measurement as a parameter to the TIMESTAMPDIFF function. So you have to write multiple LINQ Queries in scenarios where you shouldn't have to. One for dealing with weeks, a fixed interval, and another for months, which is a variable interval, for example.

Solution:

I request an added function, which takes as an additional parameter a string or an enumeration that represents a Time Unit, so that you could determine in advance of a LINQ query what the time interval unit will be. As follows:

public static int DateDiff(string unit, this DbFunctions _, DateTime startDate, DateTime endDate)

Thanks,

@lauxjpn
Copy link
Collaborator

lauxjpn commented Mar 10, 2024

The MySQLDbFunctionsExtensions class has support for many of the specific date difference operations that MySql supports through its function TIMESTAMPDIFF(TIME_UNIT, startDate,endDate), but it doesn't support all of them. For example, there is no support for using QUARTER as a time metric, which you can do in MySql.

#1876 will address this first part of your request. It will probably be backported to 8.0.

(We will address the second part in a different PR.)

@lauxjpn
Copy link
Collaborator

lauxjpn commented Mar 12, 2024

Reopened to track implementing the second part of the proposal.

@lauxjpn lauxjpn reopened this Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants