Reputation: 183
I have a script that im working on that has a the need for me to determine what week of the year i am in. and this has to go year by year.
So the script must determine the week of the year i am on now. ie week 33 then it must also work out that last week was week 32 and next week 34
I will then be able to match them up with the database and pull out only content for this week.
i have simple named the weeks a number in the database... ie... 34 33 and 35
Please see attached image
Any help appreciated ! Ta
Upvotes: 0
Views: 87
Reputation: 18440
Using PHP's DateTime class:-
$week = (int)(new \DateTime())->format('W');
$previousWeek = $week - 1;
$followingWeek = $week + 1;
Upvotes: 0
Reputation: 14233
if you want to do it in MySQL then (I think this can force the MySQL not to cache the query so there can be a performance issue)
SELECT WEEK(now())
Upvotes: 1