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 4 of 4

Thread: comparing dates

  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    53
    Thanks
    0
    Thanked 0 Times in 0 Posts

    comparing dates

    hi

    i want to compare two dates called booking_start_date and booking_end_date to make sure that the booking start date comes before the booking end date.

    at the moment both dates are just stored as dates in the mysql database.

    anybody know how i could do this?

    and also does anybody know how i can find the number of days that the booking is for based on the dates that the user has entered as it will be needed for me to calculate the price of their overall booking

    thanks

  • #2
    Regular Coder goughy000's Avatar
    Join Date
    Nov 2005
    Location
    England
    Posts
    415
    Thanks
    0
    Thanked 0 Times in 0 Posts
    with PHP timestamps its easy to find how many days between 2 dates.

    (enddate-startdate)/secondsinaday

    www.php.net/date
    www.php.net/time


    it depends what format they are in your database as though
    PHP Freelancing!
    ByteForums!
    Scriptlance.comNeed a job done quick? post it on scriptlance! OR! your a programmer? sign up and get paid for these jobs!

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Since you are working with data in a database, let the database do the calculations for you. You can use datediff to find the difference between the dates.

    you can also take a look at the article in my signature on room reservations which will show you how to check for vacant rooms when you want to do a booking.

  • #4
    New Coder
    Join Date
    May 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try with this function
    //you have to input $dt_start, $dt_end dates as this format
    //yyyy-mm-dd
    /*if your date is not in above format use php preg_split function to split your date by perticular characters then re organize them acording to above mentioned format.*/
    enjoy...
    function is_date_greater($dt_start, $dt_end)
    {
    if(strtotime($dt_end) > strtotime($dt_start) )
    {
    return true;
    }
    return false;
    }


  •  

    Posting Permissions

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