Magento format DateTime using Configuration options.Playing with magento date and time comparing with php date and time format.
Magento format DateTime using Configuration options.

In this tutorial I am going show you how we can manage Magento format DateTime using Configuration options.In magento we don’t need to define time zone through our code side as it can declare in backend side by the dir System => configuration => General => Locale Option => Timezone.lets talk for Magento format DateTime using Configuration options.Before to explain everything about magento date and time formatting I would like show you the core function of magento. Which we should call for formatting our date and time if we will format Magento format DateTime using Configuration options for our custom code or custom module.

If you navigate dir : app/code/core/Mage/core/Helper/Data.php then you will getting two function one is for date formatting called formatDate() and other is formatting time called formatTime().So if you understand below two functions well then your most of problem on Working with php and magento dates is resolved now.In the same way we can refer model class of date for other date and time formatting functions.If you will navigate through dir : app/code/core/Mage/core/Model/Date.php

FormatDate Function:

formatTime Function:

Above two functions are core functions I have shown here for your references not to edit direct to these functions of helper file.What we need to do is we just need to these function wherever we want.Lets see how we can call on different situations.

Current Default Type Date Format:

Out Put:

2015-03-28 11:24:32

Current Formatted Date Format:

Out Put:

2015-03-28

Formatted Type Date Format:

Or

Out Put:

28.03.2019

Above two different examples are for formatting date format own your desire format.But if you will like to use only in magento way then see below examples where I have explained how magento uses different date format.

Default date format:

Medium Type

Out Put:

Mar 28, 2015

Short Type

Out Put:

3/28/15

Long Type

Out Put:

March 28, 2015

Full Type

Out Put:

Friday, March 28, 2015

In same way you can use to formatting time with magento default format replacing formatDate function to formatTime function like.

Default time format:

Medium Type

Out Put:

4:00:00 PM

Short Type

Out Put:

5:00 PM

Long Type

Out Put:

5:00:00 PM PDT

Full Type

Out Put:

5:00:00 PM America/Los_Angeles

All the results are coming due to configuration of magento in backend.

Magento format DateTime using Configuration options
Tagged on:                     

3 thoughts on “Magento format DateTime using Configuration options

  • October 22, 2016 at 3:27 am
    Permalink

    Hi,
    How do i restrict date range in custom option and disable old dates in calendar for custom option ?

    Thanks

    Reply
    • October 22, 2016 at 9:31 am
      Permalink

      Can you please provide the screen shot where you want to restrict date range ? However you can restrict date range in JavaScript(prototype) just like jquery date picker.

      Reply
  • November 15, 2016 at 12:59 pm
    Permalink

    Here i founded one bug in your Time Format. Please replace from “formatDate” to “formatTime” on Different Time format.

    Reply

Leave a Reply

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