DateTimeFormat Process

This example shows the usage of DateTimeFormat process

namejoined_date
John 2018-08-01 01:34:12
Marry 2018-09-12 10:22:44
Peter 2018-09-03 13:44:14
Donald 2018-09-26 17:27:54

->pipe(new DateTimeFormat(array(
    "joined_date"=>array(
        "from"=>"Y-m-d H:i:s",
        "to"=>"M jS, Y",
    )
)))
namejoined_date
John August 1st, 2018
Marry September 12th, 2018
Peter September 3rd, 2018
Donald September 26th, 2018

The example demonstrates usage of DateTimeFormat process. The DateTimeFormat used to format the datetime column from a format to another. The usage is very straight forward, you enter the current format of your datetime column and the format you want to convert to.

The DateTimeFormat support formatting many columns at same time, for example:

->pipe(new DateTimeFormat(array(
    "joined_date"=>array(
        "from"=>"Y-m-d H:i:s",
        "to"=>"F jS, Y",
    ),
    "leaved_date"=>array(
        "from"=>"Y-m-d H:i:s",
        "to"=>"F jS, Y",
    ),
)))
<?php
require_once "MyReport.php";

$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../../koolreport/autoload.php";

use \koolreport\processes\ColumnMeta;
use \koolreport\processes\DateTimeFormat;

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    protected function settings()
    {
        return array(
            "dataSources"=>array(
                "data"=>array(
                    "class"=>'\koolreport\datasources\ArrayDataSource',
                    "dataFormat"=>"table",
                    "data"=>array(
                        array("name","joined_date"),
                        array("John","2018-08-01 01:34:12"),
                        array("Marry","2018-09-12 10:22:44"),
                        array("Peter","2018-09-03 13:44:14"),
                        array("Donald","2018-09-26 17:27:54"),
                    )
                )
            )
        );
    }
    protected function setup()
    {
        //Prepare data
        $this->src("data")
        ->saveTo($source);

        //Save orginal data
        $source->pipe($this->dataStore("origin"));
        
        //Pipe through process to get result
        $source->pipe(new DateTimeFormat(array(
            "joined_date"=>array(
                "from"=>"Y-m-d H:i:s",
                "to"=>"F jS, Y",
            )
        )))
        ->pipe($this->dataStore("result"));
    }
}
<?php
    use \koolreport\widgets\koolphp\Table;
    use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
    <div class="text-center">
        <h1>DateTimeFormat Process</h1>
        <p class="lead">This example shows the usage of DateTimeFormat process</p>
    </div>
    
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("origin"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>

<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new DateTimeFormat(array(
    "joined_date"=>array(
        "from"=>"Y-m-d H:i:s",
        "to"=>"M jS, Y",
    )
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>

    <div style="margin-top:20px;">
    <?php
    Table::create(array(
        "dataSource"=>$this->dataStore("result"),
        "cssClass"=>array(
            "table"=>"table-bordered table-striped table-hover"
        )
    ));
    ?>
    </div>

</div>

What People Are Saying

"KoolReport helps me very much in creating data report for my corporate! Keep up your good work!"
-- Alain Melsens

"The first use of your product. I was impressed by its easiness and powerfulness. This product is a great and amazing."
-- Dr. Lew Choy Onn

"Fantastic framework for reporting!"
-- Greg Schneider

Download KoolReport