| 

Joomlapolis! News

Be the first to know our latest news and releases!

twitter

facebook Joomlapolis RSS News Feed

How to make a date ordered CB list with automatic record aging

Have you ever wanted to create a list that is ordered and displayed by date, but age the records so that only the last 30 days display? Perhaps a list like "Users Added In The Last 30 Days". In my case I have the ability for members to note a significant life announcement like a birth or marriage. Since they are not likely to remove it in a timely fashion, I would like to prevent any that are older than 180 days from displaying.

SQL has many powerful capabilities within query statements. Small pieces of programmatic code can be inserted in query statements - this tip takes advantage of that capability. MYSQL will automatically handle your date field correctly whether it is a date time field like "Member Since" or just a date field such as a CB custom date field. Here is how you create a list that automatically stops displaying records that are a certain number of days older than the current date. For this example we will display member records created in the last 30 days.

Detailed Steps
Create a new list and ensure that it is sorted in descending order by the date field that you are intrested in aging the records by. This date field does not actually have to be displayed in your list - but in most cases it helps users understand that the list is somehow date dependent. For the "Filter" select "Advanced" and place this code in field:

DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= `registerDate`
DATE_SUB(CURDATE(), INTERVAL 30 DAY) defines a small subroutine that filters all dates including today and 30 days in the past.

<= `registerDate` "pushes" the registerDate field into this code fragment. You can also combine the date filter with any other criteria as well - here is one that shows records where a custom annoucement text field is not blank and the custom announcement date field is not older than 60 days:

`cb_announcementtextcustomfield` != '' and DATE_SUB(CURDATE(), INTERVAL 60 DAY) <= `cb_announcement datecustomfield`

I am discovering that there are many other cool things that can be done via SQL queries.

Please rate this article so we know what types of Tips and Tricks are most helpful to you!

--

Latest Tweets

  • 02:05 PM May 21 2012
    Much more to come next days, weeks, months from #jab12. It was a mutually #inspiring event: most things just started there #joomla #jos
  • 12:05 AM May 21 2012
    #jab12 is a HUGE #positive success! Thanks to each participant+organiser, @brianteeman @rdeutz @vdrover @gnomeontherun #joomla #jos #share
  • 01:05 PM May 20 2012
    CB 2.0: A new way to build web apps: 2nd #JAB12 Lightning talk Live video streaming starts in 10 min: http://t.co/9PvOzLnS #joomla #jos
  • 12:05 PM May 20 2012
    Must see: "CB 2.0: A new way to build web apps" 2nd #JAB12 Lightning talk! Live video starts in 1 hour: http://t.co/W1i5iIPw #joomla #jos
  • 11:05 AM May 20 2012
    Don't miss them: #JAB12 Lightning talks start in 2 hours with live video streaming: http://t.co/J8qvNhSd #joomla #jos
  • 10:05 AM May 20 2012
    Sorry, in 3:20 hours!
  • 10:05 AM May 20 2012
    Must see: "CB 2.0: A new way to build web apps" 2nd #JAB12 Lightning talk! Live video starts in 1 hour: http://t.co/H9v47zF3 #joomla #jos
  • 10:05 AM May 20 2012
    Must see: "CB 2.0: A new way to build web apps" 2nd #JAB12 Lightning talk! Live video streaming 12:50UTC: http://t.co/51G5VZyX #joomla #jos