Re: function question
| From: | dwalker | Date: | Thu, 01 May 2003 14:29:07 +0000 |
| Subject: | Re: function question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-145964@lists.php.net to get a copy of this message | ||
try placing paren around the entire function. I think your problem may stem
from 'order of operation'.
if((futureDate($_POST[booking_date])) == 'weekend'){
echo 'date is a weekend'
}
-----Original Message-----
From: Shaun <shaun@mania.plus.com>
To: php-general@lists.php.net <php-general@lists.php.net>
Date: Thursday, May 01, 2003 8:49 AM
Subject: [PHP] function question
>Hi,
>
>I am using a function mofied from an earlier post to check whether a given
>date is valid and does not occur in the past, however when i try to use the
>function with:
>
>if(futureDate($_POST[booking_date]) == 'weekend'){
> echo 'date is a weekend'
>}
>
>and the function is returning zero, it still enters the loop and prints
>'date is a weekend'
>
>I would be grateful for your help as this doesn't make sense to me!
>
>Date checking function:
>
> function futureDate($timestamp){
> $error = 0;
> $flag = 0;
> $t = split("/",$timestamp);
> if (count($t)!=3) $t = split("-",$timestamp);
> if (count($t)!=3) $t = split(" ",$timestamp);
>
> if (count($t)!=3){
> $error = 'invalid';
> $flag = 1;
> }
>
> if (!is_numeric($t[0])){
> $error = 'invalid';
> $flag = 1;
> }
> if (!is_numeric($t[1])){
> $error = 'invalid';
> $flag = 1;
> }
> if (!is_numeric($t[2])){
> $error = 'invalid';
> $flag = 1;
> }
>
> if ($t[0]<1902 || $t[0]>2037){
> $error = 'invalid';
> $flag = 1;
> }
>
> if (date("D", mktime(0, 0, 0, $t[1], $t[2], $t[0])) == 'Sat'){
> $error = 'weekend';
> $flag = 1;
> }
> if (date("D", mktime(0, 0, 0, $t[1], $t[2], $t[0])) == 'Sun'){
> $error = 'weekend';
> $flag = 1;
> }
>
> $timeStamp = mktime(0,0,0, $t[1], $t[2], $t[0]);
> if(!($timeStamp >= time()) && $flag == 0){
> $error = 'past';
> }
> return $error;
> }
>?>
>
>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
>