lunac Posted November 14, 2006 Share Posted November 14, 2006 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? Link to comment https://forums.phpfreaks.com/topic/27269-having-trouble-pulling-dated-items-fro-db/ Share on other sites More sharing options...
Caesar Posted November 14, 2006 Share Posted November 14, 2006 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. Link to comment https://forums.phpfreaks.com/topic/27269-having-trouble-pulling-dated-items-fro-db/#findComment-124701 Share on other sites More sharing options...
lunac Posted November 15, 2006 Author Share Posted November 15, 2006 I usually do timestamps but since I only needed the date, I did date -- guess that's my mistake. I'll go back to timestamps. Thanks. Link to comment https://forums.phpfreaks.com/topic/27269-having-trouble-pulling-dated-items-fro-db/#findComment-124803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.