Brief: Am working on a CodeIgniter3.0.3 version application. It is a multi-tenant application. Single code base connects to multiple databases based on the user login (interacts with different database). Each user could be from different timezone across the globe. I am trying to apply the below code.
$time = Date('Y-m-d h:i:s');echo $time;
$expiry=$this->db->get_where('settings', array('type' => 'registration_date'))->row()->description;
echo Date('Y-m-d h:i:s',$timestamp);
The answer from Dhruv helped to some extent. But displaying previously stored dates (before implementing the timezone) was the issue. Then followed up several SO articles arrived the solution like below.
date_default_timezone_set("Asia/Kolkata"); $registered=$this->db->get_where('settings', array('type' => 'registration_date'))->row()->description; $dt_obj = new DateTime($registered); $dt_obj->setTimezone(new DateTimeZone('Africa/Accra')); echo $dt_obj->format('Y-m-d H:i:s');
i.e., first setting the timezone as per the server, retrieve the data and convert it to display
Thanks to gzipp as mentioned in this question