KoolReport's Forum

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

DateTimePicker cant format output with date only and no time #2190

Closed cfsinc opened this topic on on Jul 7, 2021 - 2 comments

cfsinc commented on Jul 7, 2021

I cant seem to get dateTimePicker to output with only date. No matter what I try it outputs with the time also

When I try and insert into mysql in setup function I can get dateRangePicker to only give me date but not dateTimePicker

mysql log no matter what I tried so far. I need to just remove the time from the datetimepicker. As I said I can get this to work fine with dateRangePicker but this report im doing here can only function with a single date.

the query in setup

 $sql_activities = "
                            SELECT *, 
                    date_format(activity_date, '%H%:%i') AS activity_time
                    FROM activities t1
                    RIGHT JOIN users t2 ON t2.user_id = t1.activity_user_id
                    WHERE t1.activity_date >= :start
                        AND t1.activity_date <= :end
                      AND t2.user_name = :emp
                    /*AND activity_date BETWEEN '2021-07-01 00:00:00' AND '2021-07-01 23:59:59'*/
        ";

the params in setup for the sql query

        // pipe table data to activity report activities
        $this->src('lp3')->query($sql_activities)
            ->params(array(
                ":start"=>$this->params["dateTime"],
                ":end"=>$this->params["dateTime"],
                ":emp"=>$this->params["user_name_activity"]
            ))
            ->pipe($this->dataStore("activities"));

my sqllog

                    RIGHT JOIN users t2 ON t2.user_id = t1.activity_user_id
                    WHERE t1.activity_date >= '2021-07-01 00:00:00'
                        AND t1.activity_date <= '2021-07-01 00:00:00'
                      AND t2.user_name = '31'

If i cant get it to format before the setup function, how would I format the date at the step to remove the time? could I use DateTimeFormatProcess and if so can you give me an example of that used

I have tried remove it before this step and no matter what I have tried I cant get the time to remove

If i dont give daterangePicker any paramValues it defaults to date only without time

Here is my defaultParamValues I have tried

        return array(
            "dateRange",
            "user_name"=>"%",
            //"dateTime",
            //"dateTime"=>date("Y-m-d"),
            "dateTime"=>array(date("Y-m-d")),
            "user_name_activity"=>"%",
            //"dateRange_activity"=>array(date("Y-m-d"),date("Y-m-d")),
            "dateRange_activity"
        );

When I try to format in the input it will only format the view of the input

                DateTimePicker::create(array(
                    "name" => "dateTime",
                    "format"=>"YYYY-MM-DD",
//                    "options"=>array(
//                    ),
//                "value"=>"Date"
                ));

I have tried to edit the DateTimePicker.php values also and commented them out and tried to change them to date only but it still outputs date and time

       if($this->value===null)
        {
            $this->value=date('Y-m-d H:i:s');
            //$this->value=date('Y-m-d');
        }
        else
        {
            $date = new \DateTime($this->value);
            $this->value = $date->format("Y-m-d H:i:s");
            //$this->value = $date->format("Y-m-d");
        }
        $this->locale = Utility::get($this->params,"locale");
        $this->options = Utility::get($this->params,"options");
    }
Sebastian Morales commented on Jul 8, 2021

It's true that the current value format of a DateTimePicker input is fixed as 'YYYY-MM-DD HH:mm:ss'. But you could change it to any format in your report's setup like this:

function setup()
{
    $datetimeValue = $this->params["myDateTimePicker"];
       if($datetimeValue===null)
        {
            $datetimeValue=date('Y-m-d');
        }
        else
        {
            $date = new \DateTime($datetimeValue);
            $datetimeValue = $date->format("Y-m-d");
        }     
    // now use $datetimeValue in 'Y-m-d' format for your query, etc
cfsinc commented on Jul 8, 2021

Wonderful!!! Worked perfectly! I knew you guys would give me a great solution. Im working on my php. taking classes but the great product and great support has really helped!!!

I suggest to everyone that sees this forum post, if the support staff helps you out, consider clicking on the little $ icon next to their name and tip them something. Yes we buy the license and support but when you get a solution that helps and saves you lots of time, show them it matters!!!

Thank you so much!!!!!

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

Inputs