KoolReport's Forum

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

How to create custom date range #746

Closed Eugene opened this topic on on Mar 17, 2019 - 2 comments

Eugene commented on Mar 17, 2019

Hi, I try to do like this but get an invalid date message despite that the returned array consists the valid dates

 <?php DateRangePicker::create(array(
                        "name" => "dateRangeInput",
                        "format" => "Do MMM, YYYY",
                        "ranges" => array(
                            "Yesterday" => DateRangePicker::yesterday(),
                            "Last 3 days" => function(){
                                    $start = new \DateTime('now');
                                    $end = new \DateTime('now');
                                    $start->sub(new \DateInterval('P2D'));
                                    return array($start->format('Y-m-d 00:00:00'),$end->format('Y-m-d 23:59:59'));
                            },
KoolReport commented on Mar 17, 2019

On your report class, you do add last3days() method:

class MyReport exntends \koolreport\KoolReport
{
...

    function last3days()
    {
        $start = new \DateTime('now');
        $end = new \DateTime('now');
        $start->sub(new \DateInterval('P2D'));
        return array($start->format('Y-m-d 00:00:00'),$end->format('Y-m-d 23:59:59'));
    }
}

and then in the view you can do:

 <?php DateRangePicker::create(array(
                        "name" => "dateRangeInput",
                        "format" => "Do MMM, YYYY",
                        "ranges" => array(
                            "Yesterday" => DateRangePicker::yesterday(),
                            "Last 3 days" => $this->last3days()
...
Eugene commented on Mar 17, 2019

Thank you. It works

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
help needed
solved

Inputs