KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Timestamp format not working #1462

Open Arun opened this topic on on May 28, 2020 - 1 comments

Arun commented on May 28, 2020

(https://cdn.koolreport.com/assets/images/editor/c4/image5ecf7d08c8909.png)

Timestamp format not working.

"2017-03-06 10:19:25.684244" "2017-03-06 10:19:25.684244" "2017-03-06 10:19:25.684244"

This format Timestamp not working.

protected function setup()
{
    $this->src('sakila_rental')
    ->query("SELECT write_date,code FROM account_account")
    
    /*->pipe(new ColumnMeta(array(
    "write_date"=>array(
    "type"=>"datetime",
    "format"=>"Y-m-d H:i:s.u"
     )
     )))
    ->pipe(new TimeBucket(array(
        "write_date"=>"quarter"
    )))*/
    
    ->pipe(new Custom(function($data){
$data["write_date"] = $data["write_date"]->format("Y-m-d H:i:s");
return $data;

})) ->pipe(new ColumnMeta(array(

    "write_date"=>array(
    "type"=>"datetime",
    "format"=>"Y-m-d H:i:s"
)

)))

    ->pipe(new Group(array(
        "by"=>"write_date",
        "sum"=>"code"
    )))
    ->pipe($this->dataStore('sale_by_month'));


} 

I,m trying this code not working.

David Winterburn commented on May 28, 2020

Hi,

If you want to convert the format of the datetime string please use the Custom process like this:

->pipe(new Custom(function($data){
    $dateString = $data["write_date"]; //$data["write_date"] is a string, not a datetime object
    $myDateTime = DateTime::createFromFormat('Y-m-d H:i:s.u', $dateString); //assuming $dateString is like "2017-03-06 10:19:25.684244"
    $data["write_date"] = $myDateTime->format('Y-m-d H:i:s'); //format datetime object back to string to $data
    return $data;
}))

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None