What is the best way to choose the current week in MySQL?

At the moment, I have something like this ...

SELECT SUM(a.PaidSingle) AS PaidSingle,
       DATE_FORMAT(a.TimeIn, '%a') AS weekDay
FROM Attendance AS a JOIN MemberDetail AS m ON m.id = a.MemberID
WHERE m.CardNumber = '$cardNo'
AND   WEEK(a.TimeIn, 0) = WEEK(NOW(),0)
GROUP BY weekDay
ORDER BY a.TimeIn

But after me it was understood when I wrote that this would happen both in previous years and this year.

I just wanted to say and year = this year, but, of course, in the week starting in December and ending in January, I get only half an hour.

What is the best way to do this in MySQL or should I use a PHP based solution?

+5
source share
2 answers

WEEK = 0, 0 53, ,   "YYYY53", "YYYZ00", .

2, DATE_FORMAT% V % X:

DATE_FORMAT( NOW( ), "%X%V" )

1 53, YYYY53 YYYZ.

!

+3

:

SELET DATE_FORMAT(NOW(), '%u')

0

All Articles