Add Start and End Date limit Joomla 1.5 Banners

On my recent project which uses Joomla v1.5, my client asks for banner management with ability to manage banner based on number of impression or date (period of time). Quick search on Joomla extension repositories show that there are many banner management component and module for Joomla 1.0 but not Joomla 1.5. Most of them which run on 1.5 are module to add animation or customize the display of your banner. At the time I write this blog, I found one component which does this, but it’s fairly plain and does not allow me to limit the banner based on number of impression made, categorize my banners, and keep track of clients.

Fortunately, the default Joomla 1.5 comes with com_banners and mod_banners core component and it has everything I need except start and end date setting to publish banner/ads. So let’s modify this core component to add this feature.

There are two files that you need to edit. First, open up \administrator\components\com_banners\views\banner.php with your favourite editor. Then insert the following codes on line 347 (between </tr> and <tr>).

<?php // BEGIN EDIT - Enable Start and End Date of Banner
	function formatToShortDate($date) {
		$date = substr($date,0,10);
		if ($date == '0000-00-00') return "";
		return $date;
		<td class="key">
			<?php echo JText::_( 'Start Date' ); ?>
	  <?php echo JHTML::_('calendar', formatToShortDate($row->publish_up) , 'publish_up', 'publish_up', '%Y-%m-%d', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?></td>		
		<td class="key">
			<?php echo JText::_( 'End Date' ); ?>
	  <?php echo JHTML::_('calendar', formatToShortDate($row->publish_down) , 'publish_down', 'publish_down', '%Y-%m-%d', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?></td>		
	// END EDIT - Enable Start and End Date of Banner

Secondly, locate and edit \components\com_banners\models\banner.php.
Try to find this line $wheres[] = ‘(imptotal = 0 OR impmade < imptotal)’;. On my file it’s located on line number 41, and below that add the following code:

// BEGIN EDIT - Enable Start and End Date of Banner
$wheres[] = "(publish_up = '0000-00-00 00:00:00' OR publish_up <= CURDATE())";
$wheres[] = "(publish_down = '0000-00-00 00:00:00' OR publish_down >= CURDATE())";
// END EDIT - Enable Start and End Date of Banner

It’s done. Now you will have start and end date field when you create new or edit your banners. The mod_banners will only display ads/banners which sit after the start date (if set) and before the end date (if set). You can leave start and end date field empty to ignore them. Please leave comments if you are satisfied or face any problem. Cheers.

44 Replies to “Add Start and End Date limit Joomla 1.5 Banners”

  1. Great hack! so simple yet so handy and powerful!!
    Should really be a feature in core joomla banner code, especially if it’s this easy to do.

  2. How do I remove the year? so it is only the date ex: 02-06 it is looking at.

    I want to use it for an event that happens at the same date every year.
    Like a birthday.

    1. Thank you for all of the comments guys, really appreciate them.
      For Morten, to limit the banner to show at certain date, you just need to change the $wheres[].
      the simplest way will be :
      INSTEAD OF putting :
      $wheres[] = “(publish_up = ‘0000-00-00 00:00:00’ OR publish_up < = CURDATE())"; $wheres[] = "(publish_down = '0000-00-00 00:00:00' OR publish_down >= CURDATE())”;
      You will use :
      $wheres[] = “MONTH(publish_up) = MONTH(CURDATE()) AND DAYOFMONTH(publish_up) = DAYOFMONTH(CURDATE())”;
      in this case you will keep entering the year in admin, but it will be ignored. I haven’t test this yet, so yeah give it a go. Cheers.

    1. Great πŸ™‚ hope it helps… Share the “giving” lifestyle πŸ™‚
      You can post other questions if you face other difficulties with Joomla, or if you need my professional service to develop Joomla module/component πŸ™‚

  3. I do not have the \components\com_banners\models\banner.php file on my system. no ‘models’ directory at all.

    Any help?

  4. This is interesting, I don’t know if a new or modified Joomla 1.5 Ad. comp. ot module/plugin is now available to do this. Is there one?

    Is it possible to have a feature where a given email is sent by the system when say the clients Ad. is one month from “renewal”?

  5. Gr8 mod! I was looking for it for a while. But i was searching for something with date and time to start or stop πŸ™‚ I made a little variation of yours. Now i can set publish and end to a specific date and time :)! Thx for your work. If you want, contact me, and i will send you my version πŸ™‚

  6. I made these changes but it doesn’t work for me. The module reverts back to unlimited impressions and the banners continue to show after I set a stop date. I eneter stop dates for all the banners and when I checked a few months later all the banners had reverted to unlimited impressions. Can you help

  7. I’m having the same problem as Jill – it used to work, but ever since I updated to 1.5.15 (not even the latest version) the hack doesn’t work and the banners are running past their end dates. Any answers? Really loved it when it worked though πŸ™‚

  8. I’ve always wondered why Joomla has a start and endate in the banners database table, but doesn’t use it. While it’s so easy to implement in the interface.

  9. First I would like to thank the solution presented.
    Almost fully met my needs (and many others, I’m sure).
    Want more tips on how to use a field in the full format of Joomla, with the date and time.
    Again thanks,

  10. Thanks a lot, very useful. Is there any way how tu unpublish banner after expiration date? Any tips how to do it? Anyway, thanks.

  11. Gr8 help provided…worked perfect for me. It will help those who r not much into coding, still want to develop site in joomla. Thanks. πŸ™‚

  12. Hi, this is a great hack. Must be in the Joomla core features!

    I made ​​some little changes to publish banners for one day:

    publish_up , ‘publish_up’, ‘publish_up’, ‘%Y-%m-%d 00:00:00’, array(‘class’=>’inputbox’, ‘size’=>’25’, ‘maxlength’=>’19’)); ?>

    publish_down , ‘publish_down’, ‘publish_down’, ‘%Y-%m-%d 23:59:59’, array(‘class’=>’inputbox’, ‘size’=>’25’, ‘maxlength’=>’19’)); ?>


    $wheres[] = “(publish_up = ‘0000-00-00 00:00:00’ OR publish_up = NOW())”;


  13. Wow…Amazing pal. this is exactly what i need. all d best for u future jobs, but we are expecting more than this from you, this is our kindly request..

  14. am struggling with joomla1.5 blog component (lyften bloggie) can you slove my problem (there is no option for reply the comment ) thanks in advance

  15. That is great but since it is now core feature of Joomla 1.6 , we need one step further.

    How can we make banners “rotate” on based of time and/or day of week

    That would be really helpful

  16. i wonder how hard it would be and what might been needed to add a published until column to the banners listing page?

    thanks for this.

  17. thanks
    my banner after passed date for veiw , that is viewed and i can see that on my site.
    i do start date and end date point.but dos not work for me

    please help me

Leave a Reply

Your email address will not be published. Required fields are marked *