Jump to content

change style if date is older than 14 days


Recommended Posts

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); ?>

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);
}

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);
}

<?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.

Archived

This topic is now archived and is closed to further replies.

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