【问题标题】:To Convert CST to IST timezone将 CST 转换为 IST 时区
【发布时间】:2019-03-20 18:33:06
【问题描述】:

我的实际要求是,

这是我们在 .txt 文件中的输入,

下面的行包含 (Emp ID, Date, HH:MM:SS (即时间), Status, Site number, Reader number

123,"20/02/2019",00:00:50,IN,23,1

在上面,我必须将 123 作为 Emp ID,并将其分配给一个名为 tv_emp_id 的变量。

then, have to take date and HH:MM ("20/02/2019",02:30) and convert it into IST date & time (21-02-2019,14:00)), then put date (21-02-2019 format) alone in one variable called tv_date and HHMM in another variable called tv_time (14:00 it will be 1400) by Oracle query.

Finally required it with, tv_emp_id= 123;
           tv_date = 21-02-2019
           tv_time = 1400

请帮我解决。

谢谢

【问题讨论】:

  • 请编辑您的问题以包含示例数据 - 特别是起始数据类型 - 和结果。
  • 为什么是 12:29 而不是 12:30?这些是日期还是时间戳?
  • 什么是时区 CST 和 IST?看看SELECT TZABBREV, TZ_OFFSET(TZNAME), TZNAME FROM V$TIMEZONE_NAMES WHERE TZABBREV in ('CST', 'IST')

标签: sql oracle timezone


【解决方案1】:

如果您的意思是 Central Standard Time and India Standard Time,并且您从一个普通的时间戳开始:

alter session set nls_timestamp_format = 'YYYY-MM-DD HH24:MI:SS';
alter session set nls_timestamp_tz_format = 'YYYY-MM-DD HH24:MI:SS TZD';

select timestamp '2019-03-20 02:00:00'  as original,
  from_tz(timestamp '2019-03-20 02:00:00', 'America/Chicago') as cst,
  from_tz(timestamp '2019-03-20 02:00:00', 'America/Chicago') at time zone 'Asia/Calcutta' as ist
from dual;

ORIGINAL            CST                     IST                    
------------------- ----------------------- -----------------------
2019-03-20 02:00:00 2019-03-20 02:00:00 CDT 2019-03-20 12:30:00 IST

如果您想以纯时间戳(或日期)结束,而不是带时区的时间戳,则将结果大小写为您想要的数据类型。

如果您从某个日期开始,则需要将其转换为 from_tz() 调用中的时间戳。

【讨论】:

    猜你喜欢
    • 2014-05-11
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2021-04-10
    相关资源
    最近更新 更多