SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Me With Php The Checks Start Date And End Date

    Hello,
    May someone help me with a a php script or date calander that will enable users of the form to pick or select the start and end date. The start date should be equal to the current or future date and end date should be equal to start date or future date.
    Have come have scripts below but is not working properly.
    The date is being picked or selected using javascript calander, when I submit it gives error.
    The script is as follows,

    $tDepartureDatett =$_POST["Departure_Date"];//start date
    $tReturnDatett =$_POST["Return_Date"];// end date

    $tDepartureDate=date("$tDepartureDatett");
    $tReturnDate=date("$tReturnDatett");

    $testDate=(($tDepartureDate>=$dtoday) and($tReturnDate>=$tDepartureDate));

    if($testDate==0){
    echo"Check the Dates";
    echo "<br>";
    echo "<br>";
    echo"Departure Date must be today or future date";
    echo "<br>";
    echo "<br>";
    echo"Return Date must be equal to Departure Date or greater";
    echo "<br>";
    echo "<br>";
    echo "<a href=javascript:history.Back()>Back</a>";
    exit;
    }
    elese {

    It does want I want

    }

    Date format is YYYY-MM-DD e.g 2006-09-1



    Iam receiving this error


    Warning: mktime() [function.mktime]: Windows does not support negative values for this function in c:\local\wamp\www\subsistence\test888.php on line 44

    Warning: mktime() [function.mktime]: Windows does not support negative values for this function in c:\local\wamp\www\subsistence\test888.php on line 46

    when I use the scripts below
    of course iam using windows operating system in as webserver


    $dtoday = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y"));

    $tDepartureDatett = $_POST["Departure_Date"];//start date
    $tReturnDatett = $_POST["Return_Date"];// end date

    $tDepartureDate = mktime (0, 0, 0, date ("m",$tDepartureDatett), date ("d",$tDepartureDatett), date ("Y",$tDepartureDatett));

    $tReturnDate = mktime (0, 0, 0, date ("m",$tReturnDatett), date ("d",$tReturnDatett), date ("Y",$tReturnDatett));

    $testDate = ( ($tDepartureDate >= $dtoday) && ($tReturnDate >= $tDepartureDate) );

    if ( !$testDate ) {
    echo "Check the Dates";
    echo "<br>";
    echo "<br>";
    echo "Departure Date must be today or future date";
    echo "<br>";
    echo "<br>";
    echo "Return Date must be equal to Departure Date or greater";
    echo "<br>";
    echo "<br>";
    echo "<a href=javascript:history.Back()>Back</a>";
    exit;
    } else {

    so want is the solution


    Your help will be highly appreciated.
    Thanks.
    Last edited by zamzam; Apr 6, 2006 at 04:28.

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What is the actual format of the date information in the $_POST variables?
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Date format is YYYY-MM-DD e.g 2006-09-1

  4. #4
    SitePoint Addict Chillijam's Avatar
    Join Date
    Nov 2003
    Location
    England
    Posts
    293
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If strtotime (http://php.net/strtotime) doesn't do what you want, you can split the string with explode() (http://php.net/explode) to give you
    $split[0] = year
    $split[1] = month
    $split[2] = day
    After that, you can convert to unix time (for comparisons) with mktime() (http://php.net/mktime)

    HTH
    Your mind is like a parachute. It works best when open.
    (HH The Dalai Lama)

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    UNTESTED!!

    PHP Code:
    $dtoday mktime (000date ("m"), date ("d"), date ("Y"));

    $tDepartureDatett $_POST["Departure_Date"];//start date
    $tReturnDatett $_POST["Return_Date"];// end date

    $tDepartureDate mktime (000date ("m",$tDepartureDatett), date ("d",$tDepartureDatett), date ("Y",$tDepartureDatett));

    $tReturnDate mktime (000date ("m",$tReturnDatett), date ("d",$tReturnDatett), date ("Y",$tReturnDatett));

    $testDate = ( ($tDepartureDate >= $dtoday) && ($tReturnDate >= $tDepartureDate) );

    if ( !
    $testDate ) {
        echo 
    "Check the Dates";
        echo 
    "<br>";
        echo 
    "<br>";
        echo 
    "Departure Date must be today or future date";
        echo 
    "<br>";
        echo 
    "<br>";
        echo 
    "Return Date must be equal to Departure Date or greater";
        echo 
    "<br>";
        echo 
    "<br>";
        echo 
    "<a href=javascript:history.Back()>Back</a>";
        exit;
    } else {
        
    // It does want I want

    Ian Anderson
    www.siteguru.co.uk


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •