Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DROP TABLE IF EXISTS `tb_sys_vars`;
- CREATE TABLE `tb_sys_vars` (
- `sys_vars_name` varchar(255) NOT NULL,
- `sys_vars_value` varchar(255) NOT NULL,
- `tgl_jam_buat` datetime DEFAULT NULL,
- `tgl_last_update` datetime DEFAULT NULL,
- UNIQUE KEY `sys_vars_name` (`sys_vars_name`)
- );
- 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');
- 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');
- 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');
- DROP PROCEDURE IF EXISTS `st_get_datetime`;
- CREATE PROCEDURE `st_get_datetime`(OUT svrDateTime datetime)
- BEGIN
- DECLARE timeZone VARCHAR(255);
- DECLARE timeZoneDiff INTEGER;
- SELECT
- MAX(CASE WHEN sys_vars_name = 'time_zone' THEN sys_vars_value END) AS time_zone,
- MAX(CASE WHEN sys_vars_name = 'time_zone_diff' THEN sys_vars_value END) AS time_zone_diff
- FROM tb_sys_vars
- INTO timeZone, timeZoneDiff;
- SET time_zone = IFNULL(NULLIF(timeZone,''),'Asia/Jakarta');
- SELECT DATE_ADD(NOW(), INTERVAL IFNULL(timeZoneDiff,0) HOUR)
- INTO svrDateTime;
- END;
- DROP FUNCTION IF EXISTS `fc_get_datetime`;
- CREATE FUNCTION `fc_get_datetime`() RETURNS datetime
- BEGIN
- DECLARE tglNow DATETIME;
- CALL st_get_datetime(tglNow);
- RETURN tglNow;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement