I want to show the badge nuevo
, for this I was trying the following code but it always shows me that it is new:
The code I am using:
function NewProduct(){
$DateProduct = '2010-01-10 00:00:00';
$days = 5;
$offset = $days*60*60*24;
if ($DateProduct < date('U') - $offset ) {
echo '<span class="new-product">NEW</span>';
}
}
NewProduct();
There are a couple of problems with the logic:
fecha_de_producto
>= current_date - 5 daysThe first thing to do is convert the product date to a timestamp with
strtotime()
, then subtract 5 days from the current date and do the comparison.