4
I want to subtract the current system date with the date that is saved in mysql. I insert the date into mysql via INSERT, manually, because I will not always use the current date to insert into the system.
I need to know how many days there are of difference between the current date and the registered date.
It’s for a library system, where I enter the date the book was borrowed. in the book report, if the current date - the registration date is greater than or equal to 8 ( >= '8' ) should show that it is delayed by so many days. but I’m not getting it. I got lost in the middle of the code because of the dates.
fico grato se alguem puder me ajudar
$sql_visualizar = mysql_query ("SELECT * FROM cadastro_alunos ORDER BY serie, numero, data");
while ($linha = mysql_fetch_array ($sql_visualizar)){
$pega_numero = $linha ['numero'];
$pega_aluno = $linha ['nome'];
$pega_serie = $linha ['serie'];
$pega_n_livro = $linha ['n_livro'];
$pega_livro = $linha ['livro'];
$pega_emprestado = $linha ['emprestado'];
$pega_data = $linha ['data'];
$data_sistema = $linha [date("d-m-Y")];
//aqui é para comparar as datas, se a data do emprestimo for maior que 8 dias (o sistema conta um dia a mais) realizar a função $pega_atraso
$pega_atraso = $data_sistema - $pega_data;
?>
<?
if ($pega_emprestado == 'sim'){
?>
//aqui fica os campos da tabela que uso, por isso estes não precisam aparecer aqui.
<?
//aqui é onde se encontra a função do atraso
if ($pega_atraso >= '8'){
echo "ENTREGA ATRASADA EM $pega_atraso dias";
else
echo "No prazo de Leitura";
}
?>
What format do you receive from the bank at
$pega_data = $linha ['data'];
? In time: Why should we not use mysql type functions_*?– gustavox
received in standard format ('Y/m/d')
– Guilherme Henrique
So try to use
$data_sistema = $linha [date("Y-m-d")];
...– gustavox
And you also need to Contact Datetime object (or use
ceil
as in Alan’s reply) before comparing the dates, I will post a more detailed answer, but I think the ideal is to do it directly in SQL itself, in the line of Willian’s reply...– gustavox