Christian Page
Christian Page

Reputation: 151

Get rows from db within the week of NOW()

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

Answers (4)

Prashanth
Prashanth

Reputation: 341

This would help you

for Mysql date functions

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

Muhammad Raheel
Muhammad Raheel

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

mic4ael
mic4ael

Reputation: 8290

I think that BETWEEN might be what you want.

Upvotes: 1

Haneev
Haneev

Reputation: 775

You can use the function WEEK(date) of mysql.

SELECT a FROM t WHERE WEEK(deadline_date) = WEEK(NOW())

Upvotes: 4

Related Questions