Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
I ned help creating a query that shows the number of days left before the end of the term. I need the following functions to ac...Asked by Kwadwo
I need help creating a query that shows the number of days left before the end of the term. I need the following functions to accomplish this: CONCAT, DAYOFYEAR, NOW. So far I have this for my query:
SELECT CONCAT('There are ',DAYOFYEAR(NOW()),' ',DAYOFYEAR(NOW())) AS `Days Left`;
The result is supposed to say: There are 69 days left before school ends for the spring term!!!
The result I got was: There are 79 79
SELECT CONCAT('There are ',DAYOFYEAR(NOW()),' ',DAYOFYEAR(NOW())) AS `Days Left`;
The result is supposed to say: There are 69 days left before school ends for the spring term!!!
The result I got was: There are 79 79
Answers
Answered by
MathMate
There are a few things to note:
1. You need to have a date to specify the end of the term, or else SQL has no way to get the answer you want.
2. The result 79 represents the number of days since January 1st of the year, which correspond to about March 20th.
3. 79 appeared twice because the expression DAYOFYEAR(NOW()) appeared twice.
4. Finally, to find the number of days left, you need to subtract one date from the other, something like:
DAYOFYEAR('2011-06-03')-DAYOFYEAR(NOW())
Assuming 3rd of June is the last day of the term.
1. You need to have a date to specify the end of the term, or else SQL has no way to get the answer you want.
2. The result 79 represents the number of days since January 1st of the year, which correspond to about March 20th.
3. 79 appeared twice because the expression DAYOFYEAR(NOW()) appeared twice.
4. Finally, to find the number of days left, you need to subtract one date from the other, something like:
DAYOFYEAR('2011-06-03')-DAYOFYEAR(NOW())
Assuming 3rd of June is the last day of the term.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.