php day counting system

Asked

Viewed 114 times

0

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

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 no longer new... if it is negative (false), it is new.

Reference issue: Fetch last 7 days data from current date

  • I will implement here I will test if any error occurs posted here I am finishing another part of the project thanks for the reply

0

As I imagine you wish to bring the object regardless of whether it is 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;
}

Hence just do what you want based on the content of $novo: whether you will display an image, a button etc.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.