Querying a date

Hi guys,

Im after a pointer in the right direction. Im trying to query a database uisng the date field in the table but something keeps going wrong.

Ive managed to get everything to work except the where clause.

I want to able to query:

SELECT blah FROM blah
WHERE table.date_end > today BUT < + 2 months…

So greater than today but less than 2 months in the future.

The date field is and SQL dat field ie (YYYY-MM-DD).

Can anyone suggest a where clause for e please??

You’re close:

SELECT blah FROM blah
WHERE table.date_end BETWEEN CURDATE() AND CURDATE() + INTERVAL 2 MONTH;

Damn it, i was close…

I initially had the ‘CURDATE() + INTERVAL 2 MONTH’ bit but removed it because it wasnt showing everything between then and today.

So all was needed from my original query was a BETWEEN.

Ah well, its only easy when you know how…

Thanks very much for the help transio.

Any time, homie! You may also want to reference mysql.com for questions about specific functions… it’s not a great general reference, but if you know what you’re looking for, it gives you a good amount of detailed knowledge (even if in a cryptic way!)

Ah thats great,

I thought id learn PHP and MYSQL using the hands on approach, So far i havent done to badly i dont think.

I started by creating a basic web based Clocking In/Out application but this query is for my second project which is a web based customer and contract database.

So any other useful resources you have i would be grateful…

Thanks again.

There is also a MySQL forum, here in the SitePoint forums (MySQL - SitePoint Forums)