-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
#17170 - DATEDIFF Week Implementation #17226
Conversation
/// <param name="_">The DbFunctions instance.</param> | ||
/// <param name="startDate">Starting date for the calculation.</param> | ||
/// <param name="endDate">Ending date for the calculation.</param> | ||
/// <returns>Number of year boundaries crossed between the dates.</returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number of week not year
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I really missed it.
.GetWeekOfYear( | ||
startDate, | ||
CalendarWeekRule.FirstFullWeek, | ||
DayOfWeek.Monday); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it matters but in most places the first day of the week is Sunday
/// <param name="_">The DbFunctions instance.</param> | ||
/// <param name="startDate">Starting date for the calculation.</param> | ||
/// <param name="endDate">Ending date for the calculation.</param> | ||
/// <returns>Number of year boundaries crossed between the dates.</returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number of weeks instead of year
DATEDIFF always uses Sunday as the first day of the week to ensure the function operates in a deterministic way. |
kkk, I climbed my last test, was testing some possibilities. I was sure it was sunday. |
cda8acd
to
245ce03
Compare
@@ -880,6 +881,97 @@ private static bool ContainsCore(string propertyName, string searchCondition, in | |||
? (int?)DateDiffNanosecond(_, startTimeSpan.Value, endTimeSpan.Value) | |||
: null; | |||
|
|||
/// <summary> | |||
/// Counts the number of year boundaries crossed between the startDate and endDate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
year
-> week
8a98a15
to
badf500
Compare
@ralmsdeveloper thanks for your effort, could there's a parameter to specific the the first day of week, the Monday is the first day of the week for China in most cases |
@smitpatel Note that this isn't a priority; we're not taking this for 3.0. |
No. That is not possible. According to SqlServer documentation |
@shimingsg thanks for your info, got it from the docs here also
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need more testing as requested.
We can't do this, sql server uses deterministically Sunday, that means the translation will not match the SQL Server result. https://docs.microsoft.com/pt-br/sql/t-sql/functions/datediff-transact-sql?view=sql-server-2017 @WeihanLi |
badf500
to
1d612bd
Compare
Done! |
Merging to release/3.1 in #17726 @ralmsdeveloper - Thank you for contribution. |
Resolve #17170