FishWagon Posted October 2, 2009 Share Posted October 2, 2009 Hello everyone, Complete PHP n00b here... I am retrieving values from a database recordset. One of the columns has dates in a comma delimited format. For instance: <?php echo $row_WAATKusers['selecteddates']; ?> will display: 8/15/2009, 9/22/2009,10/1/2009,10/15/2009 What I would like to do, is strip away any date older than today. So in the above string, once I parse out dates and remove the ones older than today, the only one left should be 10/15/2009 I figured I can put them into an array, then cycle through each one removing the old ones, then rebuild the string with the array elements left over, but while theory is good, putting it into code is another. Then again, that may be overly complicated and there may be a simpler approach. Can anyone shed some light as to how I should go about this? Thank you very much, have a great day, Rich Quote Link to comment https://forums.phpfreaks.com/topic/176314-stripping-out-old-dates/ Share on other sites More sharing options...
taquitosensei Posted October 2, 2009 Share Posted October 2, 2009 where do you actually do your querying of the database? Because that's where you'd do this. select columns from table where datefield >= today Quote Link to comment https://forums.phpfreaks.com/topic/176314-stripping-out-old-dates/#findComment-929252 Share on other sites More sharing options...
FishWagon Posted October 2, 2009 Author Share Posted October 2, 2009 Thank you for taking the time to reply taquitosensei, They are stored in the DB as that string. What this is is a calendar where people select certain dates, and the calendar passes that info off as a string of dates. The string is stored in the DB, and when people go to view their record, I take that string and pass it back to the calendar who displays the dates in the string. I want to intercept that string first and remove any dates that are older than today since they are no longer needed. That way they only see today and any future dates. Then when they leave, I will store that "new" string back to the db. And then round and round we go for future trips. Quote Link to comment https://forums.phpfreaks.com/topic/176314-stripping-out-old-dates/#findComment-929261 Share on other sites More sharing options...
RussellReal Posted October 2, 2009 Share Posted October 2, 2009 I'm assuming the datefield is just a text field since your dates are 'xx/xx/xxxx' instead of 'xxxx-xx-xx' DELETE FROM table WHERE STR_TO_DATE(datefield,'%m/%d/%y') < NOW() Quote Link to comment https://forums.phpfreaks.com/topic/176314-stripping-out-old-dates/#findComment-929271 Share on other sites More sharing options...
FishWagon Posted October 2, 2009 Author Share Posted October 2, 2009 Thanks for your time Russell, The column may have multiple dates in it. For instance, Let's say we have 3 people, Rich, Laura, and Kyle. So we have 3 records in the database. Rich selects 2 dates, so his recordset has this in the selecteddates column: 9/27/2009,10/1/2009 Laura has 5 dates selected, so her record has in the selecteddates column: 8/15/2009,8/19/2009, 9/22/2009,10/1/2009,10/15/2009 Kyle only selected one date, so his record only has this in the selecteddates column: 9/29/09 So if Laura logs in, what I get back from the database in the selecteddates column is: 8/15/2009,8/19/2009,9/22/2009,10/1/2009,10/15/2009 When they go into their profile page, the calendar control on the page receives that string, and by the dates contained in that string, knows what days to "highlight" on the calendar itself. So what I need to do, before taking the string out of the single recordset for that person, is to take out the old dates. I understand the sql query, but like I said, the column has a string of dates, not a single date. So I figured I have to manipulate the string after receiving it from the DB. Clear as mud? Hahaha Thanks again all, Rich Quote Link to comment https://forums.phpfreaks.com/topic/176314-stripping-out-old-dates/#findComment-929280 Share on other sites More sharing options...
RussellReal Posted October 2, 2009 Share Posted October 2, 2009 you should use a different format for your database.. you should make a new row for each date set.. for example: TABLE: dates id | uid | name | dateField | 1 | 12 | Bud | 05/30/1990 | 2 | 12 | Bud | 10/20/2009 | 3 | 10 | Paul | 10/22/2009 | then you just sort by UID to get all the dates in order of person and filtering and any other management type actions are a TON easier Quote Link to comment https://forums.phpfreaks.com/topic/176314-stripping-out-old-dates/#findComment-929283 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.