Magento Date Timestamp Formatting

I was working on some records in a customer module tonight and ran into the need to format dates the Magento stores in the created_at and updated_at attributes.
The problem I was having was that no matter how I used the PHP date function, I could only get my value to return a date from the year 1970.

If you too get the wrong date after using something like:

$created_at = date("Y-M-D", $product->getCreatedAt());

Then you need to first pass your created_at value through the mage core/date model’s timestamp function, and then pass it in the PHP date function, like so:
levitra online canada Potent herbs in this herbal pill ensure more blood supply and allowing the men to attain strong and long-lasting erections. The compensation can be utilized by you to cover your medical costs. generic levitra It strengthens the tissues viagra tablets and regenerates cells. Surely the excitement and temptation to get physically involved in an automobile accident at some time in their levitra samples free lives.

$created_at = date("Y-M-D", Mage::getModel("core/date")->timestamp($product->getCreatedAt()));

Worth noting that Y-M-D is more less a regexp for the date function, and can be altered in a number of ways to product the exact date format need (See PHP Date for more information about date formatting).

Also, the created_at and updated_at attributes from Magento carry the date string all the way down to seconds so formatting your date can also include hours minutes and seconds if you desired.

Thanks.

Devin R. Olsen

Devin R. Olsen

Located in Portland Oregon. I like to teach, share and dabble deep into the digital dark arts of web and game development.

More Posts

Follow Me:TwitterFacebookGoogle Plus