Closed Thread
Results 1 to 10 of 10

Thread: between dates query

  1. #1
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Question between dates query

    im having trouble with between dates.. when i run this with mySQL its working properly but when i insert this in php its not working.. im searching but cant get any results.. thanks.
    this is working fine.
    SELECT * FROM guest_info where room_type = '$mode' and check_in = '$check_in' and check_out= '$check_out';
    but when i add the between -.- nothing happens
    SELECT * FROM guest_info where room_type = '$mode' and check_in = '$check_in' and check_out= '$check_out' between '$check_in' AND '$check_out';
    thanks

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: between dates query

    This is an example using between
    Code:
    Where Stu_Dob Between '1984-01-01 00:00:00' And '1986-1-1 00:00:00';
    just a drop of dew in the morning
    ( loop while (= x true) do (x) )

  4. #3
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: between dates query

    i've seen that example on web and tried that but unfortunately.. its not working lol

    i dont know why when i add the "BETWEEN" its as if its not reading my query im using the YYYY-MM-DD format

  5. #4
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: between dates query

    you must match the date format when 'select and insert' query, format must be the same

    see format of date in php. you can customize it as you want

    PHP: date - Manual
    just a drop of dew in the morning
    ( loop while (= x true) do (x) )

  6. #5
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: between dates query

    im using sql and php isame format YYYY-MM-DD

    I need to retrieve the records which are between the selected days(TWO dates are of two different fields)

  7. #6
    abdul.gafur's Avatar
    abdul.gafur is offline Learning Programmer
    Join Date
    Mar 2010
    Location
    Salo, Riau, Indonesia
    Posts
    42
    Rep Power
    0

    Re: between dates query

    You have to retrieve two of dates before

    $first_date; //date from your database field
    $second_date; //date from your database field

    The following code is way to use between.
    Code:
    SELECT * FROM your_table WHERE your_field BETWEEN '$first_date' AND '$second_date'
    just a drop of dew in the morning
    ( loop while (= x true) do (x) )

  8. #7
    hardinera's Avatar
    hardinera is offline Learning Programmer
    Join Date
    Jul 2009
    Posts
    42
    Rep Power
    0

    Re: between dates query

    thats not working with php....

    my question is when i insert the "BETWEEN" the query is not working -.- i tried to search on google with this issue but i cannot find any answer this is frustrating...

  9. #8
    zeroradius's Avatar
    zeroradius is offline Speaks fluent binary
    Join Date
    Feb 2008
    Location
    Ohio
    Posts
    1,403
    Rep Power
    25

    Re: between dates query

    Do you have it set to print out an error if the querry fails? If so is it giving you one? If it is not set to give an error than do this

    Code:
    $query "select BLAHAHAHAHAHAHAHAHA"// whatever your query was
     
    $run mysql_querry($query)or die(mysql_error());// or die mysql_error() will do just as it sounds return an error if a problem occurs. 
    let us know the error or if it dose not return one after adding the or die, let us know. This will help us to find the problem

  10. #9
    Eric The Red is offline Newbie
    Join Date
    Jan 2010
    Location
    Off the left coast of Canada
    Posts
    20
    Rep Power
    0

    Re: between dates query

    I scratched my head long and hard trying to figure out how to do this and what I came up with was this:

    Code:
    SELECT whatever FROM calendar WHERE (':laterdate' > check_in) AND (':earlierdate' < check_out)
    This checks to see if the date you selected is in the calendar or not. Hopefully that is what you are after...

  11. #10
    Arctic Fire is offline Learning Programmer
    Join Date
    Aug 2009
    Posts
    48
    Rep Power
    0

    Re: between dates query

    Well, in that second query, you don't have anything to be checked to see if it's between $check_in and $check_out. Are you trying to see if the current date is between those two values?

    Code:
    SELECT * FROM guest_info WHERE room_type = '$mode' AND check_in = '$check_in' AND check_out= '$check_out' AND CURDATE() BETWEEN '$check_in' AND '$check_out';

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. increment dates
    By hardinera in forum PHP Development
    Replies: 9
    Last Post: 03-28-2010, 06:56 PM
  2. Between dates
    By hardinera in forum PHP Development
    Replies: 0
    Last Post: 03-15-2010, 11:39 PM
  3. JavaScript Dates - Get Methods
    By chili5 in forum JavaScript Tutorials
    Replies: 3
    Last Post: 10-19-2009, 04:40 PM
  4. Sqlite3: How to calculate the difference of two dates?
    By Lance in forum Database & Database Programming
    Replies: 8
    Last Post: 03-06-2009, 02:00 PM

Tags for this Thread

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