liamloveslearning Posted May 13, 2010 Share Posted May 13, 2010 Hi everyone, I have a table showing a list of data, I need to change a table row if one of the values is older than 14 days old, Im inputting the date in my table as a varchar where i manualy type 10/10/1010 as i couldnt get the date input to work. is it possible to have a style which changes if the data in the table is 14 days older than the current date? my current echo script is <?php echo KT_FormatForList($row_rsworksorders1['intraprio'], 20); ?> Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/ Share on other sites More sharing options...
andrewgauger Posted May 13, 2010 Share Posted May 13, 2010 change the db structure to: when TIMESTAMP DEFAULT CURRENT_TIMESTAMP Where when is the name of your column that holds the manually entered date property. Then all you need to do is compare if($row['when']+1209600 < time()) { //todo:build an output that has different formatting; } else { echo KT_FormatForList($row_rsworksorders1['intraprio'], 20); } Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1057818 Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 Hi Andrew, Thanks for that, could you explain the database structure part sorry? Im still very amateur and I need to try and understand how everything works, Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1057872 Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 Ahh sorry, Ive just clicked, where you state current_timestamp though - it will be a user inputted date, not the date of input, Is this still possible? Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1057879 Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 if($row['when']+1209600 < time()) In regards to the above, if i wanted to alter it to be less than a variable, would the following be valid... if($row['when']+1209600 < '$myvariable' ) Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1057881 Share on other sites More sharing options...
andrewgauger Posted May 14, 2010 Share Posted May 14, 2010 just convert the date you have into a timestamp: $timeStmp=mktime($myvariable); if($timeStmp+1209600 < time()) { //todo:build an output that has different formatting; } else { echo KT_FormatForList($row_rsworksorders1['intraprio'], 20); } Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1058034 Share on other sites More sharing options...
liamloveslearning Posted May 14, 2010 Author Share Posted May 14, 2010 Sorry Andre that doesnt seem to be working either, Has anybody got an sql command to create a Date field? mine all seem to be illegal and its only storing 0000-00-00 Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1058143 Share on other sites More sharing options...
liamloveslearning Posted May 14, 2010 Author Share Posted May 14, 2010 Im also using a datepicker to choose the date, could this be a problem? Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1058163 Share on other sites More sharing options...
cyberRobot Posted May 14, 2010 Share Posted May 14, 2010 <?php echo KT_FormatForList($row_rsworksorders1['intraprio'], 20); ?> I'm not sure what the above echo statement is doing, but it seems like all you should need to do is a somewhat simple date comparison. You could try to do something like this: //ARRAY OF DATES USED TO TEST DATE COMPARISON $dateArray = array('2010-05-14', '2000-11-02', '2010-04-15', '2010-06-15', '2010-05-10', '2010-05-01', '2010-04-30', '2010-04-29'); //GET CURRENT DATE INFORMATION $currentYear = date('Y'); $currentMonth = date('m'); $currentDay = date('d'); //GET DATE USED TO DETERMINE IF AN ENTRY SHOULD BE STYLED $oldDate = mktime(0, 0, 0, $currentMonth, $currentDay-14, $currentYear); //subtract 14 days from the current date $oldDate = date('Y-m-d', $oldDate); //LOOP THROUGH THE ARRAY OF DATES foreach($dateArray as $dateToTest) { if($dateToTest < $oldDate) { echo "<p>$dateToTest needs to be styled; it's more than 14 days old.</p>"; } else { echo "<p>$dateToTest doesn't need to be styled.</p>"; } } Note that all of your dates will need to be formated as YYYY-MM-DD for this to work. Quote Link to comment https://forums.phpfreaks.com/topic/201623-change-style-if-date-is-older-than-14-days/#findComment-1058235 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.