Getting the right range of dates.....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Getting the right range of dates.....

Post by JPlush76 »

hey all, I'm trying to get a report that compares this weeks order totals with last weeks order totals...
I have this query for this week:

Code: Select all

<?php
SELECT sum(orders_total) as total, count(orders_id) as ordnum FROM orders WHERE TO_DAYS(NOW()) - TO_DAYS(orders_date) <= 7
?>
that gives me all orders from now to seven days ago.. .what I need is from 8 days ago to 14 days ago.

I'm not sure after read the docs how to subtract time and compare the dates. Anyone? thanks
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

bleh, got it

Code: Select all

<?php
SELECT * FROM orders WHERE orders_date < NOW() - INTERVAL 7 DAY AND orders_date > NOW() - INTERVAL 14 DAY
?>
Post Reply