Date comparison in php cannot be done

i cannot compare dates in php.My code look like this:

$sqldt="select to_char(sysdate-2,'dd-mon-yyyy') from dual";
$stmtdt = $obj->executeQuery($sqldt);
$rowdt = oci_fetch_array($stmtdt,OCI_BOTH);

$startdate = date('d/m/y', strtotime($rowdt[0]));
$enddate=date('d/m/y');
$workdate=date('d/m/y', strtotime($wdate)); //here wdate is our selected date which is passed from previous page.

echo "start date=".($startdate); //showing correctly

echo "end date=".($enddate);//showing correctly

echo "work date=".($workdate);//showing correctly


$S_WORKDATE=strtotime($workdate);
$S_STARTDATE=strtotime($startdate);
$S_ENDDATE=strtotime($enddate);

now when i compare dates like this

if($S_WORKDATE<$S_ENDDATE)
{
    echo "worked";
}
else
{
    echo "failed";
}

whatever comparison like ‘<‘ or’>’ or ‘<=’ or ‘>=’ is return incorrect result after code execution.please do help


Source: php

Leave a Reply