updatedDate within the Last 7 days?

7 posts by 2 authors in: Forums > CMS Builder
Last Post: April 14, 2015   (RSS)

By Perchpole - April 10, 2015

Hello, All -

I want to put together a simple mechanism to flag-up (category) pages which have been updated during the past week. I need to work out how to test the various factors!

In broadly simple terms (I think) I need to test whether the category['updatedDate'] falls within the period between now and 7 days ago. If so, return this category.

Does that make sense?

Perhaps I could do it with a query?

Any thoughts would be most welcome.

Thanks,

:0/

Perchpole

By Perchpole - April 10, 2015

Hi, Jerry -

Thanks for this. I knew there was a recipe similar to what I wanted in the cookbook. The only issue is that I am dealing with Category pages - so can't use a "Where" clause!

That's why I thought a straight query might be the best approach.

:0)

Perch

By gkornbluth - April 10, 2015

Hi Perch,

I never tried, but the same approach might work for an if statement

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - April 13, 2015

Hi Perch,

Any luck?

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Perchpole - April 13, 2015

Hi, Jerry -

The answer is yes - but its pretty basic...

<?php $lastWeek = strtotime('-7 days'); ?>

<?php $updateArray = array(); ?>
<?php foreach($category as $updated): ?>
<?php if(strtotime($updated['updatedDate']) < $lastWeek) {continue;} ?>
<?php $updateArray[] = $updated ?>
<?php endforeach ?>

That gives you a new array containing only those category records which were updated in the last 7 days.

I'm sure there's a smarter way of doing it with a query - but this is fit for purpose right now.

The reason I need it is because one site does not have "new" news stories. They simply update their existing static pages. This bit of code will alert visitors to the fact that certain pages have been changed.

:0)

Perch

By gkornbluth - April 14, 2015

Thanks Perch,

I've found that nothing is "basic" until you've figured it out, so thanks for sharing this.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php