Jump to content

between dates query

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
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..:confused: im searching but cant get any results.. thanks.
this is working fine.

Quote

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

Quote

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:love:

#2
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
This is an example using between
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) )

#3
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
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 :crying: im using the YYYY-MM-DD format

#4
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
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) )

#5
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
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)

#6
abdul.gafur

abdul.gafur

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
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.
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) )

#7
hardinera

hardinera

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
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 :crying: this is frustrating...

#8
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
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

$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
Posted Image

#9
Eric The Red

Eric The Red

    Newbie

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

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...

#10
Arctic Fire

Arctic Fire

    Learning Programmer

  • Members
  • PipPipPip
  • 48 posts
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?

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';