PDA

View Full Version : Dates in php


shaun.andrews
06-16-2009, 04:42 AM
I'm building the server validation receipes at the moment and I'm having trouble using the server validation on a date field when using php min and max dates. None of the php syntax's are working (eg, Time(); mktime(0, 0, 0, date("m"), date("d"), date("Y"));) But they work fine when you enter a fixed date.

I have created a test php page to set $time = Time(); and then echo $time; to see what the result of the server is and this results in: 1245152341

Is this correct? Is this where the problem could be occuring (a server problem) or should I be looking somewhere else for a problem??

Ray Borduin
06-16-2009, 08:07 AM
use:

date("m/d/y",$timevalue);

to convert your time to a date value that can be validated.

shaun.andrews
06-16-2009, 08:59 PM
Still not working...

I have tried entering the string you mentiond into the min date and still doesn't work.. I've tested the server by using:

$test = date("m/d/Y");

echo $test;

and this results in: 06/17/2009

So the server is working properly but when I enter in the server validation:

ALL formats - Selected

Min Date - date("m/d/Y");
Max Date - 01/01/2050

it lets any date before 01/01/2050 pass.. I can't work out why it's not working.

Ray Borduin
06-17-2009, 07:15 AM
That is because it is not evaluating that code and it is expecting a literal date value. Try using:

Min Date: <?php echo(date("m/d/y")); ?>

although that may not work either. Does the MinDate field have a lighning bolt next to it? If not it may not work with server code by default in that field. No worries, you should be able to update the code directly.

After applying look for the line of code where your minvalue is set and post it here. I can see if the syntax looks correct and advise you on changes.

shaun.andrews
06-17-2009, 10:43 PM
Hi Ray,

that code didn't work either, Here is the code that Validation toolkit posts after i have added date("m/d/Y"); as the min and 01/01/2009 as the max. And no the min and max fields do not have lightning bolts next to them:

$WAFV_Errors .= WAValidateDT(((isset($_POST["user_dob"]))?$_POST["user_dob"]:"") . "",true,"\b([12]\d|3[0-1]|0[1-9])\/(1[0-2]|0[1-9])\/\d{4}\b","date(\"m/d/Y\");","01/01/2009",false,".*","","",true,9);

Thankyou

Ray Borduin
06-18-2009, 08:53 AM
should probably be:


$WAFV_Errors .= WAValidateDT(((isset($_POST["user_dob"]))?$_POST["user_dob"]:"") . "",true,"\b([12]\d|3[0-1]|0[1-9])\/(1[0-2]|0[1-9])\/\d{4}\b","". date(\"m/d/Y\") ."","01/01/2009",false,".*","","",true,9);