KoolReport's Forum

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

DataStore()->max() issue #608

Closed Eugene opened this topic on on Jan 23, 2019 - 2 comments

Eugene commented on Jan 23, 2019

Hi,

I met with the issue

  1. I have a database with a table that has a column closed with the values like this 2019-01-21 23:47:56
  2. I create a datastore
    $this->src('quinos')
                 ->query("select closed from tbl_daily_procedures")
                 ->pipe($this->dataStore('end_day_date'));
    

    and get the max value $this->dataStore('end_day_date')->max('closed'); Everything is nice i get the maximum value 2019-01-21 23:47:56

But when I do like this

$this->src('quinos')
    		->query("select closed from tbl_daily_procedures")
    		->pipe(new DateTimeFormat(array(
        		"closed"=>"F j, Y"
    		)))
    		->pipe($this->dataStore('end_day_date'));

I get September 9, 2018

Eugene commented on Jan 23, 2019

I think the reason is that after DateTimeFormat the value is not a date type more but just a string... It looks not so useful if the same time I need to have the table with my date format and separate a maximum value...

Is it correct that I cannot use DateTimeFormat if I plan to use max, min etc. methods of dataStore?

KoolReport commented on Jan 23, 2019

Hi Eugene,

The datetime is saved in string format so basically the max() function compare string to string following the alphabeta. Due to the nature of format "Y-m-d H:i:s", the comparison will be correct since it organize from large item to smaller one: year month date hour minute time. While the second format "F j, Y" organize the year at the end so you will not able to compare.

So my suggestion is that, you should not format the date using DateTimeFormat in the setup(), you format the date when input into widget, for example:

Table::create(array(
     "dataSource"=>$this->dataStore("end_day_date")
    "columns"=>array(
        "closed"=>array(
            "displayFormat"=>"F j, Y"
        )
    )
))

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
solved

None