How do I insert the maximum number of days of a month via insert into codeigniter? Ex:
data | campo2 camp3
01/01/2014 |
02/01/2014 |
03/01/2014 |
. |
. |
. |
31/01/2014 |
How do I insert the maximum number of days of a month via insert into codeigniter? Ex:
data | campo2 camp3
01/01/2014 |
02/01/2014 |
03/01/2014 |
. |
. |
. |
31/01/2014 |
You can generate these dates from the following loop.
Adapt the loop according to the codeigniter insertion method (I can not remember what the Active Record syntax is like)
<?php
$dataAtual = new DateTime();
// Imprime a data atual - Teste
echo $dataAtual->format('Y-m-d') . PHP_EOL . PHP_EOL;
// 't' retorna o último dia do mês de $dataAtual
$ultimoDiaDoMes = $dataAtual->format('t');
for ($dia = 1; $dia <= $ultimoDiaDoMes; $dia++){
$diaLoop = DateTime::createFromFormat('Y-m-d', $dataAtual->format('Y-m-') . $dia);
// Aqui você insere o método para inserir no banco
// Imprime a data do loop - Teste
echo $diaLoop->format('Y-m-d') . PHP_EOL;
}
It will result in:
2014-06-09 2014-06-01 2014-06-02 2014-06-03 2014-06-04 2014-06-05 2014-06-06 ... 2014-06-28 2014-06-29 2014-06-30