开发者

PHP date() function inserting zeros into database

开发者 https://www.devze.com 2023-03-22 06:10 出处:网络
I have an array like so which has the column names of the table on the left and the associating values on the right.

I have an array like so which has the column names of the table on the left and the associating values on the right.

            $proceduredata = array 
            (
                'patient_id' => $patientfk,
                'name_id' => $procedurenamefk,
                'department_id' => $departmentfk,
                'dosage_id' => $dosagefk,
                'edocument' => NULL, //not implemented yet
                'user_id' => $this->session->userdata('userID'),
                'duration' => NULL, //not implemented yet
                'submitted' => date('d-m-Y H:i:s', now()),
                'comment' => NULL, //to be implement开发者_StackOverflow中文版ed

            );

This array is then passed into a SQL insert function. The insert works fine but my "Submitted" column is getting values of this only:

0000-00-00 00:00:00

I made sure the time formats are matching? Is there something I have missed thanks.


change the date format

  submitted' => date('Y-m-d H:i:s', now())


I believe that the "now()" function is a sql function and you are using PHP with the "date()" funciton. Try changing "now()" to "time()" which will give you a proper unix timestamp that the "date()" function can use to create a properly formatted date.

EDIT: I just realized I am not familiar with codeignighter, so please excuse me if the "now()" function is part of that framework.


now() is not a function, change now() to time(). Alternatively, date()'s second paramater is optional if you omit it date automatically uses the current date/time:

echo date('d-m-Y H:i:s');

will echo the current date/time in the format requested.

0

精彩评论

暂无评论...
验证码 换一张
取 消