Reputation: 151
I need to select all rows from the database where the rows date (deadline_date) is within the current week and deadline_date >= NOW()
. The whole goal is to show the user projects that are expiring within this week.
Not sure how to structure my query, any advice or links?
fyi, deadline_date format = 2013-12-10 00:00:00
Current query:
$query = "SELECT short_name, description, priority
FROM tasks
WHERE client_id = '$client_id'
AND deadline_date >= NOW()";
Upvotes: 1
Views: 67
Reputation: 341
This would help you
and to find day of week in php
$dayofweek = date('w', strtotime($date));
$result = date('Y-m-d', strtotime(($day - $dayofweek).' day', strtotime($date)));
Upvotes: 0
Reputation: 19882
You can use this
SELECT
short_name,
description,
priority
FROM tasks
WHERE client_id = '$client_id'
AND deadline_date > DATE_SUB(NOW(), INTERVAL 1 WEEK)
Upvotes: 0
Reputation: 775
You can use the function WEEK(date)
of mysql.
SELECT a FROM t WHERE WEEK(deadline_date) = WEEK(NOW())
Upvotes: 4