Jump to content

Having trouble pulling dated items fro db


lunac

Recommended Posts

Ok, so I have two columns `startdate` date NOT NULL default '0000-00-00',`enddate` date NOT NULL default '0000-00-00'
right now I have two rows: (1, 'f_2006', 'Fall 2006', '2006-09-11', '2006-11-18') (2, 'w_2007', 'Winter 2007', '2007-01-07', '2007-03-17');

I'm trying to query that db based on the date. I tried to do :
[code]
$q = mysqlSelect('SELECT * FROM sessions WHERE startdate < ' . date('Y-m-d'));
while ($i = mysql_fetch_assoc($q)){
$m .= $i['session'];
}
return $m;
[/code]
that returns nothing.

So I tried:
[code]
$q = mysqlSelect('SELECT * FROM sessions');
while ($i = mysql_fetch_assoc($q)){
if($i['startdate'] < date('Y-m-d')){
$m .= $i['session'];
}
}
return $m;
[/code]
that returns the fall session but not the winter one -- strange since 2007 is greater that 2006.

Any suggestions?
If at all possible (Second time saying it this week), do not store dates after you have formatted them. Store them in the database as timestamps! This makes it easy to compare strings, write conditional statements, sort data, format it diferent ways for display purposes....just overall much more flexible.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.