CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Searching Date Span

Print topic Send  topic

Author Message
Koren
Posted: 10/18/2005, 11:29 AM

I have a table (MySQL) that lists the Start_Dates and the End_Dates [of Shows] in seperate fields. I need for the user to run searches on these dates to provide the list of shows running in the span that they will be visiting. I found an excerpt from a post months ago that I think covers what I need. the only thing is I think it was written for a different setup then mine (PHP, MYSQL, CCS). How should I implement this query and is it me (I am a new) or does this syntax look not quite right for my setup? I am interested in Senario 2 mentioned below:

Quote :
Posted: 12/02/2004, 4:56 AM
You may also want to consider using SQL similar to that displayed below. This way, you'll also derive those records that "occur" within the date range where the start date and end date span the date range.

In other words, let's say that the user selected January 2005 as the date range.

Scenario 1:
date_start >= '1/1/2005' and date_end <= '1/31/2005'

Record # date_start date_end
1 1/3/2005 1/29/2005

gives you only those records where the start and end date are within that range. If that is your intention, that's fine.

However, consider scenario 2.

Scenario 2
sSQL = "SELECT * FROM Events "
sSQL = sSQL & "WHERE " sSQL = sSQL & "('" & dteToday & "' BETWEEN date_start AND date_end) OR "
sSQL = sSQL & "('" & dteStart & "' BETWEEN date_start AND date_end) OR "
sSQL = sSQL & "('" & dteEnd & "' BETWEEN date_start AND date_end) OR "
sSQL = sSQL & "(date_start BETWEEN '" & dteStart & "' AND '" & dteEnd & "') OR "
sSQL = sSQL & "(date_end BETWEEN '" & dteStart & "' AND '" & dteEnd & "')"

This SQL will not only derive the same records as derived from scenario 1, plus it will also derive records where "Today" is between the date_start and date_end...

Record # date_start date_end
1 1/3/2005 1/29/2005
2 12/9/2004 2/9/2005

In this instance you'll notice that the date range of record 2 falls within the selected date range... it 'spans' that range.


The SQL in each scenario is valid according to the effect desired. Just something to consider as at some stage - each of us hits a snag that requires the SQL similar to that shown in Scenario 2.

We hope this is helpful to you and others.
_________________
www.DataObjx.net[/quote]
Koren
Posted: 10/18/2005, 12:20 PM

:-/
I think I MAY of figured it out. My search also includes searches for "Show Titles" and "Theaters" too. this was the SQL query:
  
WHERE show_id = {show}  
AND theater_id = {theatre}  
AND ( start_date <= '{e_date}'  
AND end_date >= '{s_date}' )  
ORDER BY show  

This seems to pull all the shows that run WITHIN the search range. In my meager tests, it seems to work. Please let me know if there might be a better way.

Thanks!

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.