Jump to content

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.

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.