Answer the question
In order to leave comments, you need to log in
How to send multiple dates to db?
Hello. My column is of type DATE. But for some reason php does not process this code correctly:
$from = new DateTime('2016-01-31');
$to = new DateTime('2016-02-04');
$period = new DatePeriod($from, new DateInterval('P1D'), $to);
$array_dates = array_map(
function($item){return $item->format('Y.m.d');},
iterator_to_array($period)
);
$date_string = implode(',',$array_dates);
mysqli_query($connect, "INSERT INTO `date` VALUES (".$date_string.")");
Answer the question
In order to leave comments, you need to log in
php has nothing to do with
DATE - it stores the date value as YYYY-MM-DD. For example, 2008-10-23.
Why did you decide that you can write several dates there separated by commas?
If you have several dates, then there should be several cells with the DATE type.
0000-00-00 is the default value for the DATE type, which is set every time an attempt is made to write heresy there.
However, you can pervert and store dates separated by commas in one cell, but of type STRING
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question