How to Update Date Attribute for All Products in Magento

attributesproduct-attribute

For 45.000+ products I want to update a specific date attribute.

I use this custom attribute "new_stock", that all needs the value of "01-01-2000".

How can I easily update this attribute for all these products?

I tried this code, inside a custom .php file and run it by browser.
But that did not work

<?php
$products = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('entity_id', array('in' => $productIds));

foreach($products as $product)
{
$product->setNewStock('2000-01-01');
// below code use for time format 
$product->setNewStockIsFormated(true);
$product->getResource()->saveAttribute($product, 'new_stock');


}?>

Best Answer

Credit to @VishwasBhatnagar for the code - I'm just clarifying what I believe the finished code should be, to do all products (the to-and-fro in the comments was getting a bit confusing I think).

<?php

ini_set('display_errors', 'On');
error_reporting(E_ALL);

require('app/Mage.php'); // this is assuming your script is located in the Magento root dir
Mage::app(); // initiate the Magento engine

$products = Mage::getModel('catalog/product')->getCollection();

foreach($products as $product)
{
    $product->setNewStock('2000-01-01');
    // this line might not be required - compare results with & without it 
    $product->setNewStockIsFormated(true);
    $product->getResource()->saveAttribute($product, 'new_stock');
}
?>