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.

Tags: , ,

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

  1. gofry Says:

    Great hack. Works perfectly.

  2. Anders Says:

    I love the powerful simplicity!

  3. Pierre Says:

    Thanks, Thanks,,, and Thanks. Good job.

  4. Seb Says:

    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.

  5. Morten G Says:

    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.

  6. admin Says:

    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.

  7. Morten G Says:

    Thanks for the replay… but I can’t get to work…

  8. Morten G Says:

    Sorry… it works… nice πŸ™‚

  9. admin Says:

    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 πŸ™‚

  10. Jonathan Says:

    For some reason this file doesn’t exist on my server:


    Do you have any suggestions? Thanks!

  11. Jonathan Says:

    Nevermind πŸ™‚ I just found the file banner/php. This hack is working perfectly. I’ve been searching for this feature for a long time. Thank YOU!

  12. Philippe Says:

    Thanks a lot mate, you did a great job !

  13. Bo Dudek Says:

    Now, that’s what I call clean’n’simple. Works like a charm, thanks dude!

    Bo Dudek

  14. Kishore Says:

    Thank you for this code. I am happy to use this code. Thank you sooooooooooooooooooooooooooooooooooooooooooooooooooooooo………. 1000 times

  15. Patrik Says:

    I have just detected this option. absolutely great!
    Thank you very much.

  16. TomHorn Says:

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

    Any help?

  17. TomHorn Says:

    DOH! … nevermind, I found it. Thanks for a great hack!

  18. Rodger Says:

    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”?

  19. Tezet Says:

    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 πŸ™‚

  20. Jill Says:

    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

  21. Amelia Says:

    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 πŸ™‚

  22. David Kurtz Says:

    So many sites and now I can thank you for making my life easier. Much Appreciated

  23. lauraneb Says:

    very good
    how to create tag to place a banner in article ?
    thanks to answers

  24. Steven Says:

    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.

  25. Fabio Lima Says:

    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,

  26. tomasTT Says:

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

  27. kanc Says:

    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. πŸ™‚

  28. Peachy Kuehn Says:

    This is a perfect solution. I manage websites for a radio station and they currently sell banner ads by run date. Thank you thank you.

  29. chanaka Says:

    thank you very much :):):)

  30. ferandreassi Says:

    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())”;


  31. Elite Webdesigners Says:

    Great hack man…life savor…now I don’t have to deal with bulky components. This is exactly what I needed…

  32. Umesh Says:

    It’s really great. thanks πŸ™‚

  33. Bhoopalan Says:

    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..

  34. Bhoopalan Says:

    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

  35. Singh Says:

    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

  36. Richard Says:

    thanks mate!

  37. modraideja Says:

    great hack, tnx so much!

  38. max Says:

    Any way to make this literally unpublish the banner after the end date?



  39. really good just what i needed Says:

    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.

  40. Benjamin Voglar Says:

    Is it possible the banners restricted by date+time, not just by date?

  41. Fred Says:

    Very easy to do. Excellent. Thanks for this.

  42. mal2moh Says:

    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

  43. mal2moh Says:

    i do srart date today and end date for 3 day but my banner dos not show ?

  44. Ω…Ψ­Ω…Ψ― Says:

    dos not work
    after insert expite date my banner dod not show
    that is bug

    please resilved

Leave a Reply