PHPackages                             ffsoft/yii2-datecontrol - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ffsoft/yii2-datecontrol

ActiveYii2-extension

ffsoft/yii2-datecontrol
=======================

Date control module allowing separation of formats for View and Model for Yii Framework 2.0

v1.9.8.1(2y ago)07.4k↓100%BSD-3-ClausePHP

Since Jun 26Pushed 2y ago2 watchersCompare

[ Source](https://github.com/ffsoft/yii2-datecontrol)[ Packagist](https://packagist.org/packages/ffsoft/yii2-datecontrol)[ Docs](https://github.com/ffsoft/yii2-datecontrol)[ RSS](/packages/ffsoft-yii2-datecontrol/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (34)Used By (0)

 [ ![Krajee Logo](https://camo.githubusercontent.com/4addfbb3869c3fc7d79befea4f06d9cf3655a686fb503df0da1d725859cfdef9/687474703a2f2f6b617274696b2d762e6769746875622e696f2f626f6f7473747261702d66696c65696e7075742d73616d706c65732f73616d706c65732f6b72616a65652d6c6f676f2d622e706e67) ](http://demos.krajee.com "Krajee Demos")
 yii2-datecontrol ---

 [ ![Donate](https://camo.githubusercontent.com/4af77d425ca202e55ab3d711b438e238ded194735bc345a019ac060e03e26227/687474703a2f2f6b617274696b2d762e6769746875622e696f2f626f6f7473747261702d66696c65696e7075742d73616d706c65732f73616d706c65732f646f6e6174652e706e67) ](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DTP3NZQ6G2AYU "Donate via Paypal")
====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#------------------------yii2-datecontrol--------------------)

[![Stable Version](https://camo.githubusercontent.com/bb3704a4682c519d99b188638776ab14e0bf2a791485c13031a1aacb566de9af/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d64617465636f6e74726f6c2f762f737461626c65)](https://packagist.org/packages/kartik-v/yii2-datecontrol)[![Untable Version](https://camo.githubusercontent.com/e5b0f9f382b5b577d2a36ccf2f9b85b279ddaefa924b99e57e72d13d19b365db/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d64617465636f6e74726f6c2f762f756e737461626c65)](https://packagist.org/packages/kartik-v/yii2-datecontrol)[![License](https://camo.githubusercontent.com/518a271f7e11a3e5470a9b0c075f8b7154c869b95a0576c13cb665c0c54e2d77/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d64617465636f6e74726f6c2f6c6963656e7365)](https://packagist.org/packages/kartik-v/yii2-datecontrol)[![Total Downloads](https://camo.githubusercontent.com/798939efd1e1f5b9ff7954307f27ac526db257b21965c547de5e2c952af702a0/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d64617465636f6e74726f6c2f646f776e6c6f616473)](https://packagist.org/packages/kartik-v/yii2-datecontrol)[![Monthly Downloads](https://camo.githubusercontent.com/82ea13aa9e269b8fad9ade552eb4d3dcb70d152dc6bd2dbd0de3eaa8d2e4f78c/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d64617465636f6e74726f6c2f642f6d6f6e74686c79)](https://packagist.org/packages/kartik-v/yii2-datecontrol)[![Daily Downloads](https://camo.githubusercontent.com/b6a0d6de155cca1ef1adb6a2c1d4cf38db0f08f0ece610a485a81632940bc2b3/68747470733a2f2f706f7365722e707567782e6f72672f6b617274696b2d762f796969322d64617465636f6e74726f6c2f642f6461696c79)](https://packagist.org/packages/kartik-v/yii2-datecontrol)

The **Date Control** module allows controlling date formats of attributes separately for View and Model for Yii Framework 2.0. It thus allows an easy way to work with dates when displaying to users in one way (format / timezone) but saving it in the database in another way (format / timezone).

> Refer [CHANGE LOG](https://github.com/kartik-v/yii2-datecontrol/blob/master/CHANGE.md) for details on changes to various releases.

> NOTE: Version 1.9.5 has BC breaking changes. A new property `widgetOptions` is available. This property will replace the `options` property for the scenario when `autoWidget` or `widgetClass` is set.

Why Date Control?
-----------------

[](#why-date-control)

When working with the great Yii Framework, one of the most common observations I had was the need to have a proper control on the date settings. The date settings for each Yii application, are unique to each application and region. Most Yii developers or users almost always need an option of displaying date and time in ONE specific format, but save them to database in ANOTHER format. So to summarize, the problem statement was:

- Lack of a single configuration method to display date &amp; times to user (or VIEW) in ONE format
- Lack of a configuration method to save date &amp; times in database (or MODEL) in ANOTHER format

Most existing Yii solutions try to overcome the above by setting the format in `model->afterFind`, present in view, then unformat it in `model->setAttribues` or `model->beforeValidate`. This was still an issue when one had many models and views in the application and changes in development cycle, had to be replicated in many places (more complex scenarios being multi-regional formats).

This module helps overcome this large gap by addressing all of these at the presentational level. The module enables one to configure the date and time settings separately for DISPLAY and SAVE. This can be setup either globally or individually at each DateControl widget level. And if this is not useful enough, it automatically enables any date/time picker widgets to be used in conjunction with this.

How this magic works, is that the extension just alters this at the presentational layer (VIEW). It automatically sets the base model input to hidden and displays a mirror input in the display format one has set. Then on each edit of the display input, the extension traps the change event, and overrwrites the hidden base model input as per the desired save format. The other good thing is, that the extension automatically triggers the javascript change event for the base model input as well. Thus all client model validations and other jquery events needed by Picker widgets are automatically triggered.

> NOTE: All date and time formats used across this module follow one standard - i.e. [PHP Date Time format strings](http://php.net/manual/en/function.date.php#refsect1-function.date-parameters). The extension automatically provides three widgets to display and control the date-time inputs.

- [\\kartik\\widgets\\DatePicker](http://demos.krajee.com/widget-details/datepicker) or [\\kartik\\date\\DatePicker](http://demos.krajee.com/widget-details/datepicker) if your format type is `date`
- [\\kartik\\widgets\\TimePicker](http://demos.krajee.com/widget-details/timepicker) or [\\kartik\\time\\TimePicker](http://demos.krajee.com/widget-details/timepicker)if your format type is `time`
- [\\kartik\\widgets\\DateTimePicker](http://demos.krajee.com/widget-details/datetimepicker) or [\\kartik\\time\\DateTimePicker](http://demos.krajee.com/widget-details/datetimepicker) if your format type is `datetime`

Module
------

[](#module)

The extension has been created as a module to enable access to global settings for your application. In addition, it allows you to read and format date times between client and server using PHP DateTime object. The DateControl widget uses ajax processing to convert display (view) format to model (save) format.

```
use kartik\datecontrol\Module;
'modules' => [
   'datecontrol' =>  [
        'class' => 'kartik\datecontrol\Module',

        // format settings for displaying each date attribute (ICU format example)
        'displaySettings' => [
            Module::FORMAT_DATE => 'dd-MM-yyyy',
            Module::FORMAT_TIME => 'HH:mm:ss a',
            Module::FORMAT_DATETIME => 'dd-MM-yyyy HH:mm:ss a',
        ],

        // format settings for saving each date attribute (PHP format example)
        'saveSettings' => [
            Module::FORMAT_DATE => 'php:U', // saves as unix timestamp
            Module::FORMAT_TIME => 'php:H:i:s',
            Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',
        ],

        // set your display timezone
        'displayTimezone' => 'Asia/Kolkata',

        // set your timezone for date saved to db
        'saveTimezone' => 'UTC',

        // automatically use kartik\widgets for each of the above formats
        'autoWidget' => true,

        // use ajax conversion for processing dates from display format to save format.
        'ajaxConversion' => true,

        // default settings for each widget from kartik\widgets used when autoWidget is true
        'autoWidgetSettings' => [
            Module::FORMAT_DATE => ['type'=>2, 'pluginOptions'=>['autoclose'=>true]], // example
            Module::FORMAT_DATETIME => [], // setup if needed
            Module::FORMAT_TIME => [], // setup if needed
        ],

        // custom widget settings that will be used to render the date input instead of kartik\widgets,
        // this will be used when autoWidget is set to false at module or widget level.
        'widgetSettings' => [
            Module::FORMAT_DATE => [
                'class' => 'yii\jui\DatePicker', // example
                'options' => [
                    'dateFormat' => 'php:d-M-Y',
                    'options' => ['class'=>'form-control'],
                ]
            ]
        ]
        // other settings
    ]
];
```

Params Configuration
--------------------

[](#params-configuration)

The extension allows configuration of `dateControlDisplay` and `dateControlSave` settings at Yii application params level. The params configuration will override the settings at the module level. This configuration is useful when one wants to dynamically change these params settings at runtime. The settings can be overridden at DateControl widget level.

Refer the [defaulting rules documentation](http://demos.krajee.com/datecontrol#defaults) for details.

DateControl
-----------

[](#datecontrol)

The main widget for rendering each date control on your views. Many settings will be defaulted from the module setup, but can be overridden at the widget level. An usage example with `ActiveForm` and using `\kartik\widgets\DateTimePicker` is shown below. Note you can pass date-time formats as supported by ICU or PHP. To set a PHP date time format - prepend the format string with `php:` as shown below.

```
echo $form->field($model, 'datetime_2')->widget(DateControl::classname(), [
    'displayFormat' => 'php:d-M-Y H:i:s',
    'type'=>DateControl::FORMAT_DATETIME
]);
```

> NOTE: With version v1.2.0 this extension can use the new Krajee jQuery library [php-date-formatter](http://plugins.krajee.com/php-date-formatter) to perform client side date format conversion instead of using ajax, for basic date formats (without timezone). The extension can thus now easily read date &amp; time stamps consistently in ONE format (PHP DateTime) across the client and server. However, it is recommended to use `ajaxConversion` if you need seamless integration with PHP DateTime functions like timezone support.

### Demo

[](#demo)

You can see detailed [documentation and usage](http://demos.krajee.com/datecontrol) and a [demonstration](http://demos.krajee.com/datecontrol-demo) on the extension.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

> Note: Check the [composer.json](https://github.com/kartik-v/yii2-datecontrol/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json.

Either run

```
$ php composer.phar require kartik-v/yii2-datecontrol "@dev"

```

or add

```
"kartik-v/yii2-datecontrol": "@dev"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

```
use kartik\datecontrol\Module;
use kartik\datecontrol\DateControl;
```

License
-------

[](#license)

**yii2-datecontrol** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 88.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~107 days

Recently: every ~409 days

Total

33

Last Release

911d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04b9aeb216da91fd04329e1c8600550aff40e27f3e79fbc847ca85b49260a881?d=identicon)[kryvel](/maintainers/kryvel)

---

Top Contributors

[![kartik-v](https://avatars.githubusercontent.com/u/3592619?v=4)](https://github.com/kartik-v "kartik-v (128 commits)")[![buga1234](https://avatars.githubusercontent.com/u/11635211?v=4)](https://github.com/buga1234 "buga1234 (10 commits)")[![Enrica-r](https://avatars.githubusercontent.com/u/2463365?v=4)](https://github.com/Enrica-r "Enrica-r (4 commits)")[![educationisenemy](https://avatars.githubusercontent.com/u/9478999?v=4)](https://github.com/educationisenemy "educationisenemy (1 commits)")[![gael-wogenstahl](https://avatars.githubusercontent.com/u/5624541?v=4)](https://github.com/gael-wogenstahl "gael-wogenstahl (1 commits)")[![nsanden](https://avatars.githubusercontent.com/u/2072064?v=4)](https://github.com/nsanden "nsanden (1 commits)")

---

Tags

formatdateyii2extensionyiicontrol

### Embed Badge

![Health badge](/badges/ffsoft-yii2-datecontrol/health.svg)

```
[![Health](https://phpackages.com/badges/ffsoft-yii2-datecontrol/health.svg)](https://phpackages.com/packages/ffsoft-yii2-datecontrol)
```

###  Alternatives

[kartik-v/yii2-datecontrol

Date control module allowing separation of formats for View and Model for Yii Framework 2.0

551.5M36](/packages/kartik-v-yii2-datecontrol)[kartik-v/yii2-widget-datepicker

Enhanced Yii2 wrapper for the bootstrap datepicker plugin (sub repo split from yii2-widgets).

1097.0M59](/packages/kartik-v-yii2-widget-datepicker)[kartik-v/yii2-date-range

An advanced Yii 2 date range picker input for based on bootstrap-daterangepicker plugin.

894.4M41](/packages/kartik-v-yii2-date-range)[kartik-v/yii2-helpers

A collection of useful helper functions for Yii Framework 2.0

883.0M29](/packages/kartik-v-yii2-helpers)[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

791.2M17](/packages/kartik-v-yii2-password)[kartik-v/yii2-icons

Set of icon frameworks for use in Yii Framework 2.0

73970.3k34](/packages/kartik-v-yii2-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
