Reputation: 31
i am currently working on codeigniter project.i have a database name is "student_detail"
the table value have like this
payment_date
1 NULL
2 NULL
3 2017-12-06 08:47:40
payment_date column is a DATETIME format
. when i print this column it returns like this
payment_date
1 1970-01-01 00:00:00
2 1970-01-01 00:00:00
3 2017-12-06 08:47:40
but i need to return as NULL not default time format.
Upvotes: 0
Views: 2337
Reputation: 313
SELECT
id, IF(payment_date='1970-01-01 00:00:00', null, payment_date) as payment_date
FROM `student_detail`
Upvotes: 0
Reputation: 111
Modify your table payment_date and set the column payment_date datatype to NULL DEFAULT NULL.
alter table payment_date modify column payment_date datetime null default null;
Upvotes: 0
Reputation: 518
Update your payment date field in database. Setit default to null.
ALTER TABLE `table_name` CHANGE `payment_date` `payment_date` DATETIME NULL DEFAULT NULL;
Upvotes: 1
Reputation: 2581
Without a PHP code we cannot help.
MySQL works as expected: http://sqlfiddle.com/#!9/7e591f/1
EDITED:
Your framework most probably converts undefined datetime NULL
to valid date time value 1970-01-01 00:00:00
which is the very beginning of PHP time - it equals to 0 (zero) second.
Some more info you can find on Codeigniter help: https://www.codeigniter.com/user_guide/helpers/date_helper.html
Upvotes: 0
Reputation: 6565
This code is just to give you an idea. I can help you precisely if you post your PHP code in question.
Before you get the date variable and print it with date("Y-m-d", strtotime($payment_date))
function, you must check if it is having NULL
value or not.
if($payment_date != NULL)
{
date("Y-m-d H:i:s", strtotime($payment_date));
}
Upvotes: 0