jingleboy99
jingleboy99

Reputation: 725

How to display weekly(Mon to Sun) data in php and mysql?

In php i can get today date/day by using : $today = date('D, Y-m-d');

If today is wednesday 8 july, i want to display data from 6 - 11 July (9, 10 and 11 will be blank). How do I do that?

Now my system is like, today is 8 July, i will display 2 - 8 july, but start on wednesday. Not very like this way. I prefer, start on Monday to sunday, then have previous and next week button.

Upvotes: 0

Views: 1488

Answers (2)

rooskie
rooskie

Reputation: 491

... WHERE  YEARWEEK( $inputdate ) = YEARWEEK( datefield) ...

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_yearweek

Upvotes: 0

Maciej Łebkowski
Maciej Łebkowski

Reputation: 3887

Use simple strtotime() to easy calculate the date of last monday.

$lastMonday = strtotime('last monday');

Be sure to check if today is not monday, because in that case it will return a date week earlier.

Upvotes: 2

Related Questions