Jump to content

Quick Query Question... 5 times fast


phpmonkey

Recommended Posts

Here\'s what I\'m trying to get:

 

How can I retrieve all the records from last month (table has date field) by looking at today\'s date.

 

This can\'t be that hard can it???

 


CREATE TABLE slota (

 showid int(10) unsigned NOT NULL auto_increment,

 date date NOT NULL default \'0000-00-00\',

 program varchar(25) NOT NULL default \'\',

 airtime1 varchar(12) NOT NULL default \'00:00 AM\',

 airtime2 varchar(12) NOT NULL default \'00:00 AM\',

 topic text NOT NULL,

 description text NOT NULL,

 category varchar(50) NOT NULL default \'\',

 audiolink varchar(100) NOT NULL default \'\',

 repeat char(1) NOT NULL default \'\',

 repeatdate date NOT NULL default \'0000-00-00\',

 duration time NOT NULL default \'00:00:00\',

 type varchar(25) NOT NULL default \'\',

 PRIMARY KEY  (showid)

) 

 

I want to:

SELECT * from slota WHERE date = \"Last Month\"

SELECT * from slota WHERE date = \"Two Months Ago\"

SELECT * from slota WHERE date = \"Three Months Ago\"

:?

Link to comment
Share on other sites

is the number of months ago going to be passed by a form? you can format it... say you have a dropdown that passes 2, for \'2 months ago,\' then create a stamp out of it. get today\'s month, subtract 2, format it like the db 0000-00-00 and query:

 

select * from slota where date < $your_formatted_date

 

i\'ve never messed with date math... there may be a better solution. :shock:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.