Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL
Author Message
CodyG
Life Cycles Becoming CPU Cycles



Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island

PostPosted: Sat Dec 10, 2005 9:09 am Reply with quote

I'm trying to extract records based on expiry date 30 days and 60 days ahead. Here is the snippet from my file. Can someone please help me sort this out? Perhaps it's staring at me and I just don't see it.


Code:
$today= time();                 //stores today's date


$thirtydays = date("Y.m.d", strtotime ("30 days"));
//$sixtydays = date("Y.m.d", strtotime ("60 days"));
echo ("Thirty Days from today is: $thirtydays<br>");
//echo ("Sixty Days from today is: $sixtydays");

// The following query *does* work, BUT I need the date after AND to be a variable, ie: $thirtydays or $sixtydays

//$query="SELECT * from inner_circle WHERE future_expire BETWEEN NOW() AND '2006-01-10'";

// The following doesn't work. :(

$query="SELECT * from inner_circle WHERE future_expire BETWEEN '$today' AND '$thirtydays'";



How can I rewrite that last query so it will work?
Thank you, oh great wise mysql gurus. I've searched high and low for the answer, but haven't got anywhere useful.

_________________
"We want to see if life is ubiquitous." D.Goldin 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Sat Dec 10, 2005 2:16 pm Reply with quote

What format is future_expire in?
 
View user's profile Send private message
CodyG







PostPosted: Sun Dec 11, 2005 8:18 am Reply with quote

Thanks Raven.

future_expire is a mysql date format.

(sorry 'bout the day delay for my response. Two minutes after I clicked the submit button Christmas chaos was unleashed and I was swept out of here to spend all day at the mall.)
 
Raven







PostPosted: Sun Dec 11, 2005 9:23 am Reply with quote

Would you do me a favor and post a record as it looks in the database, with the schema?
 
CodyG







PostPosted: Sun Dec 11, 2005 10:15 am Reply with quote

Here is the export for my test table.

Quote:

CREATE TABLE `inner_circle` (
`icid` int(5) NOT NULL auto_increment,
`realname` varchar(25) NOT NULL default '',
`location` text NOT NULL,
`member_number` varchar(15) NOT NULL default '',
`sysnick` varchar(25) NOT NULL default '',
`email` varchar(50) default NULL,
`orig_join` date NOT NULL default '0000-00-00',
`future_expire` date NOT NULL default '0000-00-00',
`notes` text,
`welcome` int(1) NOT NULL default '0',
`admin_nick` varchar(25) NOT NULL default '',
PRIMARY KEY (`icid`),
FULLTEXT KEY `realname` (`realname`,`member_number`,`sysnick`,`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

--
-- Dumping data for table `inner_circle`
--

INSERT INTO `inner_circle` VALUES (1, 'test', 'somewhere', '03TES0', 'Test', 'test@somedomain.com, '2003-05-01', '2006-05-01', 'test', 1, 'Cody');



Last edited by CodyG on Sun Dec 11, 2005 12:00 pm; edited 1 time in total 
Raven







PostPosted: Sun Dec 11, 2005 11:35 am Reply with quote

This should work

$int30 = 30;
$int60 = 60;
$query = "SELECT * from inner_circle where future_expire between now() and DATE_ADD(now(), INTERVAL $int30 DAY)";
$query = "SELECT * from inner_circle where future_expire between now() and DATE_ADD(now(), INTERVAL $int60 DAY)";
 
CodyG







PostPosted: Sun Dec 11, 2005 11:59 am Reply with quote

Smile It works! huge hugs

I learn so much from you.
 
Raven







PostPosted: Sun Dec 11, 2005 12:03 pm Reply with quote

RavensScripts
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> MySQL

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©