comparing dates

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Martin
User
Posts: 73

comparing dates

Post by Martin »

Hi there,

i think my question regards a very simple script, but one way or another I can't figure it out how to manage. This is my case:
I have a table with one field named "Volgende"; Data type DATETIME, format Date/Time. When "Volgende" does have a value more then 14 days before today (as in "now"), value is "safe";
when "Volgende" does have a value less then 14 days before today , value is "dangerzone";
and when "Volgende" does have a value bigger than today , value is "to late";

I have read tutorials, did trials (all in server events - Row-Rendered), but somewhere I don`t get the solution. Is there anyone so kind to help me out?

Many thanks,
Martin


mobhar
User
Posts: 11712

Post by mobhar »

Martin wrote:
did trials (all in server events - Row-Rendered)

Then please post your code for more discussion.


Martin
User
Posts: 73

Post by Martin »

Here is a part of the code I've tried. The code with the "//" I've also tried, addapted, tried again and so on. Because I'm blind on this (I think) easy thing I can't get it solved.

CODE:
"
// Row Rendered event
function Row_Rendered() {
// To view properties of field class, use:
//var_dump($this-><FieldName>);

//$vandaag = strtotime(date('m/d/Y');
//$vandaag = date;//('Y-m-d');
//echo " vandaag ", $vandaag;
//echo " vandaag ", date('Y/m/d');
//$rekendatum = ($this->Volgende->CurrentValue);
//echo " rekendatum ", $rekendatum;

if ($this->Volgende->CurrentValue < date('Y-m-d'))
echo "kleiner";
elseif ($this->Volgende->CurrentValue < date('Y-m-d')-14)
echo "beetje kleiner";
elseif ($this->Volgende->CurrentValue > date('Y-m-d'))
echo "groter";

//$interval = date_diff($vandaag,$rekendatum);
//$interval->format('%a days');
//echo $interval;

//$verschil = $rekendatum-$vandaag;
//echo "VERSCHIL = ", $verschil;
//$volgende = $rekendatum('Y/m/d');
//echo " volgende beurt ", $Volgende;
}

"

Thanks for you advise,
Martin.


mobhar
User
Posts: 11712

Post by mobhar »

Each time you want to do the date comparison/calculation/operation in PHP, then you need to convert the date using PHP strtotime() function.

So, change this:
if ($this->Volgende->CurrentValue < date('Y-m-d'))
echo "kleiner";
elseif ($this->Volgende->CurrentValue < date('Y-m-d')-14)
echo "beetje kleiner";
elseif ($this->Volgende->CurrentValue > date('Y-m-d'))
echo "groter";

to:
$dMinus14Days = date("Y-m-d", strtotime("-14 days"));
if (strtotime($this->Volgende->CurrentValue) < strtotime(ew_CurrentDateTime()))
echo "kleiner";
elseif (strtotime($this->Volgende->CurrentValue) < strtotime($dMinus14Days))
echo "beetje kleiner";
elseif (strtotime($this->Volgende->CurrentValue) > strtotime(ew_CurrentDateTime()))
echo "groter";


Martin
User
Posts: 73

Post by Martin »

Hi, thank you very much, it works.
Super !!


Post Reply