/    Sign up×
Community /Pin to ProfileBookmark

Check date, display image?

Currently, one part of my site is displaying content via a database.
One of the fields it pulls is ‘$adddate’.

I’m looking to add:
if ‘$adddate’ is less than seven days ago
print new.gif

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@ScleppelOct 01.2005 — If $adddate is already a unix timestamp you can do this:
[code=php]
if((mktime() - $adddate) <= 604800)
echo 'new image stuff here.';
else
echo 'too old to have the new image';
[/code]

If it's not, try using strtotime (http://www.php.net/strtotime) to get a unix timestamp.
Copy linkTweet thisAlerts:
@lavashark_comauthorOct 01.2005 — thanks. I'll try that today and let you know how things go.
Copy linkTweet thisAlerts:
@lavashark_comauthorOct 02.2005 — They all display "too old to have new image" without any errors etc.

I might now assume that it isn't a unix timestamp?
Copy linkTweet thisAlerts:
@NogDogOct 02.2005 — Give this a shot:
[code=php]
if(time() - strtotime($adddate) <= 60*60*24*7)
{
# output the image
}
[/code]
Copy linkTweet thisAlerts:
@lavashark_comauthorOct 02.2005 — Tried this:

[code=php]<? if(time() - strtotime($adddate) <= 60*60*24*7)
{
<img src="../images/new.gif" width="19" height="9" border="0">
}

?> [/code]


and got some errors.

couldnt parse line 95 or something.

Line 95 = <img src="../images/new.gif" width="19" height="9" border="0">

different way to output image?

print perhaps?
Copy linkTweet thisAlerts:
@ScleppelOct 02.2005 — You have to echo/print it.
[code=php]
echo '<img src="../images/new.gif" width="19" height="9" border="0">';
[/code]
Copy linkTweet thisAlerts:
@lavashark_comauthorOct 02.2005 — hey man it worked great. thank you for your help.
Copy linkTweet thisAlerts:
@lavashark_comauthorOct 02.2005 — by the way:

what's wrong with this code,

(I'm trying to add; "if not less than three days, add bullet")
[code=php] <?

if(time() - strtotime($adddate) <= 60*60*24*3)
{
echo '<img src="../images/new.gif" width="19" height="9" border="0">';
}

{else echo '<img src="images/bullet_b.gif" width="11" height="9" border="0">';
}

?> [/code]
Copy linkTweet thisAlerts:
@lavashark_comauthorOct 02.2005 — (man i'm smart! :rolleyes: )

[code=php]<?

if(time() - strtotime($adddate) <= 60*60*24*3)
{
echo '<img src="../images/new.gif" width="19" height="9" border="0">';
}

else

{
echo '<img src="images/bullet_b.gif" width="11" height="9" border="0">';
}

?> [/code]


(thanks again)
Copy linkTweet thisAlerts:
@NogDogOct 02.2005 — LOL - glad you got it working.
×

Success!

Help @lavashark_com spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...