This topic is locked

Check if Date value is within limits

1/20/2009 2:40:55 PM
PHPRunner General questions
vin7102 author

Hi,
I'm want to check if the date picked by the user falls within the 2 dates shown.

Im currently using the following code which works fine for the first condition, but the 2nd condition fails by 1 day.

I want the user to only select days between the given monday and its following sunday (which are "Week_Begin" and "Week_End") and they are present on the add page.

The "Date" value is what the user selects from the picker.
Here's what I have:

if($values["Date"]<$values["Week_Begin"])

{

$message="<div class=message><<< "."Database NOT updated .........Date entered is Before the week starting date.....Select another date"." >>></div>";

return false;

}

elseif($values["Date"]>$values["Week_End"])

{
$message="<div class=message><<< "."Database NOT updated .........Date entered is After the week ending date.....Select another date"." >>></div>";

return false;

}

else

{

return true;

}


Its a Kicker because everything works great except if the user selects the "Week_End" date itself.

I'm Lost because the "Date" is NOT greater than "Week_End", Its Equal to it ??? so why not satisfy the condition..
Thanks

J
Jane 1/21/2009

It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

vin7102 author 1/22/2009

UPDATE** if anyone was curious to the solution for this problem,

After posting the project to the demo site, Jane had helped me through a support ticket.

this happens because there is time part in the Date field.

Here is the correct code:

------------------------------------------

if(strtotime($values["Date"])<strtotime($values["Week_Begin"]))

{

$message="<div class=message><<< "."Database NOT updated .........Date entered is Before the week starting date.....Select another date"." >>></div>";

return false;

}

elseif(strtotime($values["Date"])>strtotime($values["Week_End"]))

{

$message="<div class=message><<< "."Database NOT updated .........Date entered is After the week ending date.....Select another date"." >>></div>";

return false;

}


Thanks Jane.. I missed the "strtotime" ..
Works Perfect!

Vince