Cavemanharris
Cavemanharris

Reputation: 183

Determining the week of the year

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

enter image description here

Upvotes: 0

Views: 87

Answers (3)

vascowhite
vascowhite

Reputation: 18440

Using PHP's DateTime class:-

$week = (int)(new \DateTime())->format('W');
$previousWeek = $week - 1;
$followingWeek = $week + 1;

Upvotes: 0

Arun Killu
Arun Killu

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

Tom van der Woerdt
Tom van der Woerdt

Reputation: 29975

You only want the week number?

date('W')

Upvotes: 3

Related Questions