Creating cron script in Magento

Creating Magento cron script is very simple thing. First of all we have to create the module, (I hope that you know how to create magento module) and add in config.xml file next code:

0 1 * * *
birthday/observer::sendBirthayEmail

Next step, we have to create model file observer.php (in folder model) with method sendBirthayEmail

class Inchoo_Birthday_Model_Observer
{
 
public function sendBirthayEmail()
{
//this collection get all users which have birthday on today
$customer = Mage::getModel("customer/customer")->getCollection();
$customer->addFieldToFilter('dob', array('like' => '%'.date("m").'-'.date("d").' 00:00:00'));
$customer->addNameToSelect();
$items = $customer->getItems();
 
foreach($items as $item)
{
// send email or do something
}
 
return $this;
}
 
}

This cron will be executed every day at 01:00 AM. The important thing: You have to set cron execution on the server (www.yourstore.com/cron.php), without it will not work.