Create a series of date in php shell.
$sDate = "2018-09-03";
for($i=0;$i<5;$i++){
$number = 7*$i;
$day=date("Y-m-d",strtotime("$sDate + $number day"));
echo $day."\n";
}
The result is as below:
2018-09-03
2018-09-10
2018-09-17
2018-09-24
2018-10-01
Create a database which contain a table.
create database `test_day`;
create table test_day( `tday` date);
I want to write all dates into table test_day
.
$dsn = "mysql:host=localhost;dbname=test_day";
$con = new PDO($dsn,"root","xxxxx");
$sDate = "2018-09-03";
for($i=0;$i<18;$i++){
$number = 7*$i;
$day=date("Y-m-d",strtotime("$sDate + $number day"));
$query="insert into `test_day` (`tday`) value ($day)";
$con->query($query);
}
Now select what exactly in test_day
.
select * from test_day;
+------------+
| tday |
+------------+
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
| 0000-00-00 |
+------------+
Why can't write the day serial into test_day
?