Yearweek returns different results

Multi tool use
Why are the YEARWEEKs of the both following dates different?
Both dates (2018-12-29 AND 2018-12-30) are in the same week?
SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
SELECT CURDATE(); = 2018-12-30
SELECT YEARWEEK(CURDATE()); = 201852
mysql
add a comment |
Why are the YEARWEEKs of the both following dates different?
Both dates (2018-12-29 AND 2018-12-30) are in the same week?
SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
SELECT CURDATE(); = 2018-12-30
SELECT YEARWEEK(CURDATE()); = 201852
mysql
add a comment |
Why are the YEARWEEKs of the both following dates different?
Both dates (2018-12-29 AND 2018-12-30) are in the same week?
SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
SELECT CURDATE(); = 2018-12-30
SELECT YEARWEEK(CURDATE()); = 201852
mysql
Why are the YEARWEEKs of the both following dates different?
Both dates (2018-12-29 AND 2018-12-30) are in the same week?
SELECT YEARWEEK('2018-12-29 20:10:00'); = 201851
SELECT CURDATE(); = 2018-12-30
SELECT YEARWEEK(CURDATE()); = 201852
mysql
mysql
edited Dec 30 '18 at 3:51
Rick James
67.3k55899
67.3k55899
asked Dec 30 '18 at 0:24
itrangeritranger
123
123
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The default mode of operation of YEARWEEK
and WEEK
is set by the default_week_format
system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example
SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1)
Output:
201852 201852
add a comment |
Consider
SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday
while 2018-01-06
seems to return 201801
.
returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays
Thank you very much! How can I get the same "week-value" for both dates?
– itranger
Dec 30 '18 at 0:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974375%2fyearweek-returns-different-results%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The default mode of operation of YEARWEEK
and WEEK
is set by the default_week_format
system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example
SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1)
Output:
201852 201852
add a comment |
The default mode of operation of YEARWEEK
and WEEK
is set by the default_week_format
system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example
SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1)
Output:
201852 201852
add a comment |
The default mode of operation of YEARWEEK
and WEEK
is set by the default_week_format
system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example
SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1)
Output:
201852 201852
The default mode of operation of YEARWEEK
and WEEK
is set by the default_week_format
system variable, which defaults to 0, in which mode weeks are assumed to start on Sunday. To do your computation based on weeks starting on Monday (so that 2018-12-29 and 2018-12-30 are in the same week), use one of the modes described in the manual which supports that (1, 3, 5 and 7). So for example
SELECT YEARWEEK('2018-12-29 20:10:00', 1), YEARWEEK('2018-12-30', 1)
Output:
201852 201852
answered Dec 30 '18 at 1:03
NickNick
27.1k111940
27.1k111940
add a comment |
add a comment |
Consider
SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday
while 2018-01-06
seems to return 201801
.
returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays
Thank you very much! How can I get the same "week-value" for both dates?
– itranger
Dec 30 '18 at 0:46
add a comment |
Consider
SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday
while 2018-01-06
seems to return 201801
.
returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays
Thank you very much! How can I get the same "week-value" for both dates?
– itranger
Dec 30 '18 at 0:46
add a comment |
Consider
SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday
while 2018-01-06
seems to return 201801
.
returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays
Consider
SELECT YEARWEEK('2018-01-06'); returns 201753 -- saturday
SELECT YEARWEEK('2018-01-07'); returns 201801 -- sunday
while 2018-01-06
seems to return 201801
.
returns the year and week number (a number from 0 to 53) for a given date, looks for whole(completed) weeks which end with each saturdays. Iterates to the next value at upcoming sundays
answered Dec 30 '18 at 0:34


Barbaros ÖzhanBarbaros Özhan
12.8k71632
12.8k71632
Thank you very much! How can I get the same "week-value" for both dates?
– itranger
Dec 30 '18 at 0:46
add a comment |
Thank you very much! How can I get the same "week-value" for both dates?
– itranger
Dec 30 '18 at 0:46
Thank you very much! How can I get the same "week-value" for both dates?
– itranger
Dec 30 '18 at 0:46
Thank you very much! How can I get the same "week-value" for both dates?
– itranger
Dec 30 '18 at 0:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974375%2fyearweek-returns-different-results%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
iUo,Eev,5qiYyauvPs qieEY,ATIV7BO,9,UO x2bTcMr5G,qAm,N