Calculate the right moment with timezones

38 Views Asked by At

i have a user table with timezone (example: America/Bogota) and the timezone offset (example: -25200).

We have a webserver in germany (Europe/Berlin) and want to send emails on the right moment when the user in usa, africa or asia has 6am.

I getting the offset with the following php code and insert it in the user-table.

function delta_offset( $server_timezone, $user_timezone )
    {
        $dt = new DateTime('now', new DateTimeZone($server_timezone));
        $offset_server = $dt->getOffset();
        $dt->setTimezone(new DateTimeZone($user_timezone));
        $offset_user = $dt->getOffset();
        return $offset_user - $offset_server;
    }

 $server_tz = "UTC";
 $user_tz = $this->input->post( 'timezone' );
 $offset = delta_offset( $server_tz, $user_tz );

It seems that everything works good with the "get timezone and offset"-thing, but i dont know how to query that components in one query to get the user-items.

Can anybody give me some help or hint to solve that?

0

There are 0 best solutions below