tgmd Posted March 8, 2007 Share Posted March 8, 2007 I have a database that contains the columns keywords, month, day, year I need to search the keyword column, but here's the part I can't figure out, I need to search it within a date range. So I can search from 12/2/06 - 11/4/07 etc. I think I got most of it done, but I'm stuck on one issue. How do I get mysql/php to search a range? What I got so far: A script that can get the difference between the dates correctly (in my example it comes out as, 11, 2, 1) A basic search, where I can search by keywords and certain dates, but I cannot search by keywords in a range of dates. Any help would be greatly appreciated guys. Quote Link to comment Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 Im not sure why would you want to create 3 columns for day, month and year when you have so many formats available including timestamp, date and you can also save unix_timestamp in integer format.. You can easily query the database for date using all these 3 formats. Quote Link to comment Share on other sites More sharing options...
Livijn Posted March 8, 2007 Share Posted March 8, 2007 You can put month-day-year together in one column. It's easier to handle. Name it `date` and set it to date. You can get in data with "date(Y-m-d);" Quote Link to comment Share on other sites More sharing options...
tgmd Posted March 8, 2007 Author Share Posted March 8, 2007 Nah I can't this is part of a bigger project. The days month and year must be separate (I don't want to write a regular expression to separate them) But perhaps I could just put a time stamp in, in addition to the day, month, year. That would make more sense. How do I search within a range though? Quote Link to comment Share on other sites More sharing options...
Livijn Posted March 8, 2007 Share Posted March 8, 2007 Nah I can't this is part of a bigger project. The days month and year must be separate (I don't want to write a regular expression to separate them) But perhaps I could just put a time stamp in, in addition to the day, month, year. That would make more sense. How do I search within a range though? You can seperate them by: list($year, $month, $day) = explode('-', $row['date']); Quote Link to comment Share on other sites More sharing options...
skali Posted March 8, 2007 Share Posted March 8, 2007 If there is a date column in your table then $query = "select * from table where date between '$startdate' AND '$enddate'"; Quote Link to comment Share on other sites More sharing options...
tgmd Posted March 8, 2007 Author Share Posted March 8, 2007 Thanks! That did it for me... I barely use Mysql... Thanks again. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 8, 2007 Share Posted March 8, 2007 Just store the date as a single DATE type field. If you need the separate elements you can SELECT MONTH(datecol) as m, DAY(datecol) as d, YEAR(datecol) as y FROM mytable" Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.