PHP display based on date range

4 posts by 3 authors in: Forums > CMS Builder
Last Post: June 23, 2009   (RSS)

By ncasares - June 22, 2009

I'm trying to figure out how to display an image based on the 'updatedDate' of a record. I'd like to show the image if a record has been updated within the past 30 days. I'm sure this is simple, but I'm struggling with the function for comparing the 'updatedDate' to a day 30 days ago.

I don't want to limit the query based on date, just the display of a "new" image.

Can anyone help point me in the right direction?

Thanks!

Re: [ncasares] PHP display based on date range

By Dave - June 23, 2009

Hi ncasares,

I understand there's more to this project that Damon is quoting for you, but here's some code for the date part you asked about. It will set a variable with how many "days old" a record is based on it's date and then test that to display new for the first 30 days.

<?php
$secondsOld = time() - strtotime($record['date']);
$daysOld = intval($secondsOld/60/60/24);
?>
Days old: <?php echo $daysOld ?><br/>

<?php if ($daysOld <= 30): ?> NEW! <?php endif ?>


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] PHP display based on date range

By ncasares - June 23, 2009

Hi Dave,
Thanks for the info. I've gone ahead with a consulting project on this one, but I'm sure the info is useful to the community. Thanks.