I have table user
, it contains id_user
, username
and user_time
. And user_time
is the time a user registered, the properties is timestamp
so the output is like this:
User A | user_time > 2014-12-22 10:10:10
Then I use this query to display data per year
SELECT * FROM user WHERE user_time = YEAR(NOW());
The query works but just returns an empty row. It's not only the year, but also day, week, and month return empty rows. Why is this query not returning any data?
Click a cell in the date column of the pivot table that Excel created in the spreadsheet. Right-click and select "Group," then "Days." Enter "7" in the "Number of days" box to group by week. Click "OK" and verify that you have correctly converted daily data to weekly data.
To filter weekdays or weekend days, you apply Excel's filter to your table (Data tab > Filter) and select either "Workday" or "Weekend".
Excel conditional formatting for dates (built-in rules) Microsoft Excel provides 10 options to format selected cells based on the current date. To apply the formatting, you simply go to the Home tab > Conditional Formatting > Highlight Cell Rules and select A Date Occurring.
Problem is that you doesn't do anything with your data:
SELECT * FROM user WHERE user_time=YEAR(NOW())
Try to get the YEAR
from the user_time
too, like this, so you do compare the numbers, not timestamp
and a number:
SELECT * FROM user WHERE YEAR(user_time) = YEAR(NOW())
Or, as @ItsMe suggested:
EXPLAIN SELECT * FROM user WHERE YEAR(user_time) = YEAR(NOW())
And please, avoid the *
in your queries, this is a bad practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With