Advertisement
ferrynurr

FIX ERROR "fc_get_datetime"

Dec 20th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.59 KB | Software | 0 0
  1. DROP TABLE IF EXISTS `tb_sys_vars`;
  2. CREATE TABLE `tb_sys_vars` (
  3.   `sys_vars_name` varchar(255) NOT NULL,
  4.   `sys_vars_value` varchar(255) NOT NULL,
  5.   `tgl_jam_buat` datetime DEFAULT NULL,
  6.   `tgl_last_update` datetime DEFAULT NULL,
  7.   UNIQUE KEY `sys_vars_name` (`sys_vars_name`)
  8. );
  9.  
  10. INSERT INTO `tb_sys_vars` (`sys_vars_name`, `sys_vars_value`, `tgl_jam_buat`, `tgl_last_update`) VALUES ('kode_lokasi', '1', '2024-02-28 06:48:11', '2024-02-28 06:48:11');
  11. INSERT INTO `tb_sys_vars` (`sys_vars_name`, `sys_vars_value`, `tgl_jam_buat`, `tgl_last_update`) VALUES ('time_zone', 'Asia/Jakarta', '2024-02-28 06:48:12', '2024-02-28 06:48:12');
  12. INSERT INTO `tb_sys_vars` (`sys_vars_name`, `sys_vars_value`, `tgl_jam_buat`, `tgl_last_update`) VALUES ('time_zone_diff', '0', '2024-02-28 06:48:12', '2024-02-28 06:48:12');
  13.  
  14. DROP PROCEDURE IF EXISTS `st_get_datetime`;
  15. CREATE PROCEDURE `st_get_datetime`(OUT svrDateTime datetime)
  16. BEGIN
  17.     DECLARE timeZone VARCHAR(255);
  18.     DECLARE timeZoneDiff INTEGER;
  19.  
  20.     SELECT
  21.       MAX(CASE WHEN sys_vars_name = 'time_zone' THEN sys_vars_value END) AS time_zone,
  22.       MAX(CASE WHEN sys_vars_name = 'time_zone_diff' THEN sys_vars_value END) AS time_zone_diff
  23.     FROM tb_sys_vars
  24.     INTO timeZone, timeZoneDiff;
  25.  
  26.     SET time_zone = IFNULL(NULLIF(timeZone,''),'Asia/Jakarta');
  27.    
  28.     SELECT DATE_ADD(NOW(), INTERVAL IFNULL(timeZoneDiff,0) HOUR)
  29.     INTO svrDateTime;
  30. END;
  31.  
  32. DROP FUNCTION IF EXISTS `fc_get_datetime`;
  33. CREATE FUNCTION `fc_get_datetime`() RETURNS datetime
  34. BEGIN
  35.     DECLARE tglNow DATETIME;
  36.     CALL st_get_datetime(tglNow);
  37.     RETURN tglNow;
  38. END;
Tags: mysql
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement