Raj Raj - 6 months ago 12
PHP Question

PHP show/hide a picture based on date

I want to show a

gif
image based on my
database
date field
.

Like...

$dt = $row['PicDate']; // date is 2016-05-04 10:57:51

if($dt > strtotime('-30 days')){
echo '<img src="image/new.gif">';
}


But the problem is, the image is not showing.

What am I to do ?

Answer

$dt is a "date/time" string. To compare timestamps you should convert $dt with strtotime function:

$dt = $row['PicDate']; // date is 2016-05-04 10:57:51

if (strtotime($dt) > strtotime('-30 days')) {
    echo '<img src="image/new.gif">';
}