query problem with data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Lod
Forum Newbie
Posts: 2
Joined: Fri Oct 10, 2003 3:42 am
Location: Gardone Riviera - Brescia - Italy
Contact:

query problem with data

Post by Lod »

I have a problem about a query.

I have a table with 4 column.
1) id (INT)
2) Special_Date (VARCHAR)
3) date_start (DATE)
4) date_finish (DATE)

In a page i use the function date() to have the date of today in a varible like this:

$today = date("Y-m-d");

I need to have a query that select the records from my table where the date of today is included between date_start and date_finish..

anyone can help me?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Maybe something like:

Code: Select all

SELECT field1, field2, field3 FROM table WHERE NOW() BETWEEN date_start AND date_end
Mac
mathewvp
Forum Commoner
Posts: 28
Joined: Wed Apr 23, 2003 10:28 am

Post by mathewvp »

If you want to select all data between two dates,you can use

Select * from table where thedate>='start_date' and thedate<='end_date';

Replace all the variables with correct names
NOW() gives current date with time.
if you want todays date use CURDATE() in mysql

Select * from table where CURDATE()>='start_date' and CURDATE()<='enddate';
Lod
Forum Newbie
Posts: 2
Joined: Fri Oct 10, 2003 3:42 am
Location: Gardone Riviera - Brescia - Italy
Contact:

Post by Lod »

tnx a lot people...you are my salvation
Post Reply