Forum Moderators: coopster

Message Too Old, No Replies

Date Interval 7 Days

Showing jobs for todays date, or 7 days in future

         

brodie_r

2:52 am on Mar 6, 2006 (gmt 0)

10+ Year Member



I currently have a view_jobs page, and it shows jobs booked on the current day and 7 days either side. I want to be able to only show jobs for the current day, and 7 days in the future. This all works around my date field.

My current code is:
$query = "SELECT *, DATE_FORMAT(date, '%W (%d/%m/%y)') as dateFormatted
FROM jobs
WHERE date > DATE_SUB(CURDATE(), INTERVAL 8 DAY) ";

Ideas?

DrDoc

3:46 am on Mar 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First of all, you need to surround the name
date
with backticks ...

i.e.:

`date`

JollyK

3:53 am on Mar 6, 2006 (gmt 0)

10+ Year Member



(Backticks are a good idea, although not required in certain versions of MySQL. They'll kill you in 4+, though, I think, so it's always good to backtick field names that are also reserved words.)

If I'm understanding your question correctly, I'd try this. It should give you all dates that are Today or later (`date` >= CURDATE()) and which are also before 8 days from now (`date` < DATE_ADD(CURDATE(), INTERVAL +8 DAY)).

$query = "SELECT *, DATE_FORMAT(`date`, '%W (%d/%m/%y)') as dateFormatted FROM jobs
WHERE `date` < DATE_ADD(CURDATE(), INTERVAL +8 DAY) and `date` >= CURDATE()";

JK

JollyK

4:25 am on Mar 6, 2006 (gmt 0)

10+ Year Member



Wait, did you mean all the dates in between today and 7 days in the future, or the dates that are EXACTLY today OR exactly 7 days in the future (skipping the days between now and a week from now)?

If the latter, my query won't work, and you should probably use just = instead of < or >=.

JK

brodie_r

7:36 am on Mar 6, 2006 (gmt 0)

10+ Year Member



JollyK it worked a dream, thanks champ

JollyK

3:03 pm on Mar 6, 2006 (gmt 0)

10+ Year Member



Cool, glad I could help. :-)

JK