Selection from the database between the time interval

The table has a varchar(10) field in its rows. In it I store the date of the format DD.MM.YYYY? How to select rows from xx.yy.zzzz to At the same time, there are 4 lines for each date and are numbered 0-3 in a separate field. You need to sort by dates from 0 to 3:

xx.yy.zzzz 0
xx.yy.zzzz 1
xx.yy.zzzz 2
xx.yy.zzzz 3
..... 0 1 2 3

PS. The table is old and there is no way to change the structure. Records dofiga 😀

Answer 1, authority 100%

Who stores dates in databases like that 🙂

There are special data types DATEand DATETIMEfor dates and times. And you can select intervals with a query like:

SELECT * FROM tablename WHERE date_field BETWEEN "2012-01-01" AND "2012-01-31"


FROM tablename
WHERE date_field BETWEEN "2012-01-01" AND "2012-01-31"
ORDER BY date_field, ind_field

Where date_fieldis the date and ind_fieldis the index 0-3

Leave a reply

Please enter your comment!
Please enter your name here