Problem composing a working query with dates in DDBB
Posted: Mon Sep 07, 2009 5:36 am
Hi there!
I have a table in a database called events with the following rows:
dateopen => When the event starts, is a 'date' field.
dateclose => When the event finishes, another 'date' field
event => Description of the event
What I would like to do is to get all the values that have a coincidence in a certain period:
Let's say the period goes from $fecha1 = 2009-09-01 to $fecha2 = 2009-09-05.
This is the farest I have gone and it retruns nothing event though I have 2 events in DDBB which are:
2009-09-01 / 2009-09-05 and 2009-09-03 / 2009-09-15.
I guess there's something wrong with the syntax or maybe the operators are messy.
Any clues?
I have a table in a database called events with the following rows:
dateopen => When the event starts, is a 'date' field.
dateclose => When the event finishes, another 'date' field
event => Description of the event
What I would like to do is to get all the values that have a coincidence in a certain period:
Let's say the period goes from $fecha1 = 2009-09-01 to $fecha2 = 2009-09-05.
This is the farest I have gone and it retruns nothing event though I have 2 events in DDBB which are:
2009-09-01 / 2009-09-05 and 2009-09-03 / 2009-09-15.
I guess there's something wrong with the syntax or maybe the operators are messy.
Any clues?
Code: Select all
$sql2 = "SELECT * FROM events WHERE
((dateclose <= $fecha2) && (dateclose >= $fecha1)) ||
((dateopen >= $fecha1) && (dateopen <= $fecha2)) ||
((dateopen <= $fecha1) && (dateclose >= $fecha2))";