|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
I want build and extract data from a mysql table by date. The problem is that my table data needs to be by date range as follows.
Example: key field is DATE field row 1: 02-19-96 to 02-06-97 row 2: 02-07-97 to 01-27-98 row 3: 01-28-98 to 02-15-99 and the input for the query will come from a FORM input (without range), example: Enter birthday input value could be 05-13-96 How can I query the table and select the row with the correct range. Baffled newbie ! |
|
#2
|
|||
|
|||
|
You'll need two date fields in your table, start and end. In your form you should ask for month, day and year in seperate fields to make sure you control what order and format the data is in (make sure the year is 4 digits, possibly use an option box??). In your script (I'll use PHP for an example) you can concatenate the year-month-day fields.
$search_date=$year.'-'.$month.'-'.$day; Then your query would look like: select * from table_name where $search_date BETWEEN start_date AND end_date; Because the mysql DATE datatype uses the YYYY-MM-DD format, a string comparison (which BETWEEN will use in this instance) will work. |
|
#3
|
|||
|
|||
|
Thank you very much !
|
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Query by date range |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|