简体   繁体   中英

How to select date in different timezone?

I want to convert date to (Africa/Cairo) timezone in query result according to it's time zone stored in db for example I want to get (s_start) and convert it from (Europe/London)to (Africa/Cairo) but in the select query itself(because I print event date from query result event.start). My controller:

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class EventCalendar_model extends CI_Model {

function get_event_list() {
$aa = ($this->session->userdata(id));

$this->db->select('s_timezone,u_name,s_id,s_student,s_tutor, 
UNIX_TIMESTAMP(s_start)*1000 as start ');    
$this->db->select('s_start as start');    

$this->db->from('sessions');
$this->db->where("s_tutor", $aa );

$this->db->join('users', 'sessions.s_student = users.u_id');

$query = $this->db->get($this->event);

    if ($query) {
        return $query->result();



    }
    return NULL;
  }



}

在此处输入图像描述

Hope the below Query will help you.

SELECT UNIX_TIMESTAMP(CONVERT_TZ(`s_start`, '+02:00', @@session.time_zone)) as africa_cario_time FROM `table_name`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM