day counting system in php

0

Good morning how can I do a system that registers the current date in the bank and then I want it to show as new type so I want it while the date it was registered is less than 15 days it shows as new and then it quit how to do that?

    
asked by anonymous 20.09.2015 / 15:33

2 answers

1

In your SQL to select the date:

SELECT * FROM tabela WHERE 
data BETWEEN CURRENT_DATE()-15 AND CURRENT_DATE();

If the return is positive (true), the date is less than 15 days, then, it is not new ... if it is negative (false), it is new.

Reference issue: Search the data of the last 7 days from the current date

    
20.09.2015 / 16:01
0

As I imagine you want to bring the object independent of it being new or not, I suggest the following logic:

// $objeto é o objeto que você trouxe do banco, e possui a data como um atributo
$novo = false;
if ($objeto->getData()->diff(new \DateTime())->days <= 15) {
    $novo = true;
}

Just do what you want based on the contents of $novo : if you will display an image, a button etc.

    
21.09.2015 / 14:40