Reputation: 3329
I need to filter some results of this week and next week. But it gives me no result for this week.
I have records with the date "2013-10-25 12:00:00" and "2013-10-22 12:00:00".
I am getting current week by date('W', time())
in php and using WEEK(tdi.due_at)
in mysql query.
date('W', time())
return 43 which is current week number.
but WEEK(tdi.due_at)
returns 42 why?
Upvotes: 1
Views: 351
Reputation: 2437
Why not you subtract -1 from PHP date('W') - 1
.
or add +1 to MySQL WEEK(tdi.due_at) + 1
.
PHP Indexed with 1 and MySQL starts index with 0 like JavaScript does.
Upvotes: 0
Reputation: 204934
MySQL WEEK() has also an optional mode parameter that sets the condition when the first week of a year starts.
Upvotes: 1