D
D
del9937882016-11-17 23:19:26
PHP
del993788, 2016-11-17 23:19:26

How to send a range of dates to the database if I know the first and last?

Hello. There is such a calendar https://jsfiddle.net/jw01gosb/47/. It is necessary that after selecting certain dates, they are recorded in the database, but it is necessary that all selected dates are recorded in the table. That is: if the interval from 01/01/16 to 01/04/16 is selected, then all numbers should be written to the table: 1, 2, 3 and 4 number. I can easily create rows with the last and first dates through php in the database, but I can’t, because each month has a different number of days, and what should I do, the range will be from 29.02.16 to 03.03.16 ? In my database, the string has the value text. Tell me how to send the entire range of dates to the database?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max, 2016-11-17
@MaxDukov

select * from 
(select adddate('2010-01-01',t4.i*10000 + t3.i*1000 + t2.i*100 + t1.i*10 + t0.i) selected_date from
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t0,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t1,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t2,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t3,
 (select 0 i union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select 8 union select 9) t4) v
where selected_date between '2016-02-29' and '2016-03-16'

K
Kuzmina Maria, 2016-11-17
@orriole

while + strtotime("+1 day", $timestamp): strtotime will correctly handle adding 1 day to the specified date, taking into account the length of the month, the change in the year, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question