How to use date function properly? |
I have column name last_updated and datatype is "datetime".
When I use command line and insert "NOW()"; Its working fine but in Codeigniter active records its not working. I am Currently using Code: date('Y-m-d H:i:s'); For example in command line Code: 2015-02-17 17:24:51 But with COdeigniter its insert Code: 2015-02-17 12:54:50 and with Code: nice_date($last_update, 'd-M-Y h:m a')
I think it has nothing to do with the CodeIgniter. It has to do with your server's time which might be different than your computer's time. Or rather with the timezone. You should try putting date_default_timezone_set() in main index.php file (the one that starts up CodeIgniter). Take a look here: http://php.net/manual/en/function.date-d...ne-set.php
Website: http://avenir.ro
As mentioned, you need to call date_default_timezone_set() to set the timezone used by PHP's date functions. Given the times you posted, you would likely want to set the timezone to Asia/Kabul or Asia/Calcutta.
Alternatively, you can use date_default_timezone_set('UTC') and convert the dates for display using the proper timezone identifier (i.e. convert the date/time to the current user's timezone). |
Welcome Guest, Not a member yet? Register Sign In |