![]() |
How to use date function properly? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to use date function properly? (/showthread.php?tid=1182) |
How to use date function properly? - Vimal - 02-17-2015 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') RE: How to use date function properly? - Avenirer - 02-17-2015 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-default-timezone-set.php RE: How to use date function properly? - Vimal - 02-17-2015 computer time and mysql time is correct ![]() RE: How to use date function properly? - mwhitney - 02-17-2015 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). RE: How to use date function properly? - Vimal - 03-04-2015 Thanx now its ok ![]() |