Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Check if a date is in the past or future

    HI

    I have a form for reservation for courses where $data_course is the
    date of the course.

    I want to display error message if the date has already passed.

    The problem is that it returns the error message even if the date is future.

    Please let me know if there is any adust to do to the code below:

    $today = getdate();

    if($data_course < $today) { $errors[] = 'This course already happend';}


    Moises
    Last edited by moisesbr; 07-28-2012 at 11:15 PM.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,993
    Thanks
    15
    Thanked 233 Times in 233 Posts
    A simple way to deal with this is record the unix time of the reservation, which is just a number and can be subtracted for comparison.

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    70
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I modified it as below:

    $today = date("d-m-y");

    I tested a future and paste date and it works ok.

    Is it necessary to use strtotime function to prevent possible errors
    or does it seem ok ?

    Moises


  •  

    Posting Permissions

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