Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/176314-stripping-out-old-dates/
Share on other sites

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.

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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