installation - Mysql CONVERT_TZ returns null when using time_zone_name -
i hosting website on shared server. helpfully (not) refusing set timezone tables. not undone, set own using documentation (both ways) 1) via sql , 2 via tables in both cases tables have data. in both cases select convert_tz ('2015-09-15 23:59:00', from_tz, to_tz)
returns null.
i have tried set on windows (again both ways)
again, returns null. if use select convert_tz ('2015-09-15 23:59:00', '+2:00','-1:00')
works.
any ideas? alternatively, can provide code convert_tz
?
delimiter $$ create definer=`root`@`localhost` function `convert_tz_shared`( local_date_time timestamp, local_tz varchar(50), dest_tz varchar(50) ) returns datetime reads sql data deterministic begin declare secs int; declare local_tz_secs int; declare dest_tz_secs int; declare tmp_tz varchar(50); # convert if possible seconds if (left(local_tz,1)='+' or left(local_tz,1)='-') set @tmp_tz:=substring(local_tz,2,length(local_tz)); set @local_tz_secs:=substring_index(@tmp_tz,':',1)*3600 + substring_index(@tmp_tz,':',-1)*60; if (left(local_tz,1)='-') set @local_tz_secs:= -@local_tz_secs; end if; end if ; if (left(dest_tz,1)='+' or left(dest_tz,1)='-') set @tmp_tz:=substring(dest_tz,2,length(dest_tz)); set @dest_tz_secs:=substring_index(@tmp_tz,':',1)*3600 + substring_index(@tmp_tz,':',-1)*60; if (left(dest_tz,1)='-') set @dest_tz_secs:= -@dest_tz_secs; end if; end if; if (left(dest_tz,1)<>'+' , left(dest_tz,1)<>'-') set @dest_tz_secs:= (select # distinct n.name, n.time_zone_id, z.use_leap_seconds, tt.offset #, tt.is_dst, tt.abbreviation, # from_unixtime(t.transition_time) p, # t.transition_type_id time_zone_name n join time_zone z using(time_zone_id) join time_zone_transition t using (time_zone_id) join time_zone_transition_type tt using(time_zone_id,transition_type_id) name=dest_tz , from_unixtime(t.transition_time)<=local_date_time order from_unixtime(t.transition_time) desc limit 1); end if; if (left(local_tz,1)<>'+' , left(local_tz,1)<>'-') set @local_tz_secs:= (select # distinct n.name, n.time_zone_id, z.use_leap_seconds, tt.offset #, tt.is_dst, tt.abbreviation, # from_unixtime(t.transition_time) p, # t.transition_type_id time_zone_name n join time_zone z using(time_zone_id) join time_zone_transition t using (time_zone_id) join time_zone_transition_type tt using(time_zone_id,transition_type_id) name=local_tz , from_unixtime(t.transition_time)<=local_date_time order from_unixtime(t.transition_time) desc limit 1); end if; return date_add(local_date_time, interval (@dest_tz_secs - @local_tz_secs) second); end$$ delimiter ;
Comments
Post a Comment