S
S
Sergey2015-11-27 17:13:08
MySQL
Sergey, 2015-11-27 17:13:08

How to search by date in sql?

There is such a table:
id, title, dates_list
dates_list of type text and the data in it is stored as a string
2015-11-20|0,2016-01-03|1,2016-01-14|0
date | accessibility
How, with such a structure of data storage, can you organize a search by a range of dates in order to be able to page-by-page navigation through the search results?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-11-27
@Maasik

Normal - nothing.
Normalize the database, take out this data in a separate linked table.

A
Alexander Melnichenko, 2015-11-27
@alex87melnichenko

$is_available = 1;
$sql_query = "SELECT * FROM table WHERE dates_list LIKE '%2015-11-20|{$is_available}%' OR dates_list LIKE '%2016-01-03|{$is_available}%' OR ..."

That is, you need to break the period of time into days and look for these dates in each entry according to the template. This request is quite heavy. will work slowly on large volumes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question