Background Image
조회 수 6362 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
○ 테이블 스키마
create table  diff_datetime ( start_datetime  datetime,  end_datetime  datetime  ) ;

○ 테스트 데이타
insert into diff_datetime ( start_datetime,  end_datetime ) values (to_datetime('20160510053140','YYYYMMDDHH24MISS'), to_datetime('20160517165930', 'YYYYMMDDHH24MISS') ) ; 
insert into diff_datetime ( start_datetime,  end_datetime ) values (to_datetime('20160509000510','YYYYMMDDHH24MISS'), to_datetime('20160517090723', 'YYYYMMDDHH24MISS') ) ; 
insert into diff_datetime ( start_datetime,  end_datetime ) values (to_datetime('20160516011258','YYYYMMDDHH24MISS'), to_datetime('20160517203243', 'YYYYMMDDHH24MISS') ) ; 
insert into diff_datetime ( start_datetime,  end_datetime ) values (to_datetime('20160517011258','YYYYMMDDHH24MISS'), to_datetime('20160517203243', 'YYYYMMDDHH24MISS') ) ; 


○ SQL 
select 
      start_datetime
    , end_datetime
    ,  ( end_datetime - start_datetime ) / (1000 * 60 * 60* 24 )   || '일 ' 
     || TO_CHAR(  TO_DATETIME ('00010101000000', 'YYYYMMDDHH24MISS' )    +  ( end_datetime - start_datetime  ), 'HH24:MI:SS' ) AS diff_time   
from  diff_datetime 




○ SQL 실행결과
  start_datetime                 end_datetime                   diff_time
====================================================================================
  05:31:40.000 AM 05/10/2016     04:59:30.000 PM 05/17/2016     '7일 11:27:50'
  12:05:10.000 AM 05/09/2016     09:07:23.000 AM 05/17/2016     '8일 09:02:13'
  01:12:58.000 AM 05/16/2016     08:32:43.000 PM 05/17/2016     '1일 19:19:45'
  01:12:58.000 AM 05/17/2016     08:32:43.000 PM 05/17/2016     '0일 19:19:45'



○ 설명
일 계산은 end_datetime에서 start_datetime을 차감하면 밀리세컨드 결과가 계산 된다.
1일은 1000 밀리세컨드 * 60초 * 60분 * 24시간임으로   ( end_datetime - start_datetime )  / (1000 * 60 * 60* 24 )  으로 계산하면 된다.
참고로 예제 연산 처리순서가 나누기 연산이 더 빠르기 때문에 괄호를 사용하여 연산순서를 조정하였다.

시간 계산 부분은
TO_CHAR 함수의 날짜 포맷을 맞추기 위하여 TO_DATETIME ('00010101000000', 'YYYYMMDDHH24MISS' ) 를 사용하였다.
0001년 1월 1일에 end_datetime - start_datetime 결과를 더한 후에 시간을 추출하였다.

날짜 연산에 대한 출력을 "?일 ?시:?분:?초"로 출력 할 때는 유용한 방법이다.


  1. 큐브리드 마스터 소켓 디렉토리 변경방법

    Date2016.07.05 Category운영관리 By정만영 Views4218
    Read More
  2. Windows 환경에서 JAVA SP 사용 utf-8 한글 깨짐 해결

    Date2016.07.01 Category응용개발 By손승일 Views4592
    Read More
  3. INSTR함수 사용하기

    Date2016.06.29 Category질의작성 By엄기호 Views9254
    Read More
  4. group_concat(문자열 그룹처리) 함수 사용하기

    Date2016.06.29 Category질의작성 By권호일 Views28199
    Read More
  5. 두 datetime 연산결과를 "?일 ?시:?분:?초"로 표시하기

    Date2016.05.18 Category질의작성 By권호일 Views6362
    Read More
  6. Invalid XASL tree node content 에러

    Date2016.04.26 Category운영관리 By손승일 Views4477
    Read More
  7. ORACLE 테이블 및 컬럼 COMMENT 일광등록 스크립트

    Date2016.04.04 Category질의작성 By김창휘 Views9332
    Read More
  8. Windows에서 32bit 버전의 PHP 설치 후 CUBRID와 연동 실패 시 해결 방법

    Date2016.03.28 Category응용개발 By진우진 Views4523
    Read More
  9. 큐브리드 매니저 호스트 접속 시 JDBC 드라이버 찾을 수 없는 오류 해결

    Date2016.03.28 CategoryCUBRID 매니저 By진우진 Views6771
    Read More
  10. 스키마 및 인덱스 선언에 따른 최대 용량 산정을 위한 ROW SIZE 확인

    Date2016.03.21 Category질의작성 By성진 Views4175
    Read More
  11. Oracle UTL_ENCODE.TEXT_ENCODE를 CUBRID로 변환하기

    Date2016.03.21 Category질의작성 By김창휘 Views4644
    Read More
  12. 테이블 리스트 취합 SQL

    Date2016.03.19 Category질의작성 By김창휘 Views5520
    Read More
  13. 산술 연산 결과를 피젯수 또는 젯수의 자리 수에 맞춰 보자.

    Date2016.03.01 Category운영관리 By성진 Views4815
    Read More
  14. 테이블 컬럼 변경 및 추가

    Date2016.02.29 Category질의작성 By정만영 Views21793
    Read More
  15. CMT를 이용하여 원본 특정 테이블의 일부 데이터만 가져와 대상 테이블에 넣기

    Date2016.01.28 Category마이그레이션 By엄기호 Views4556
    Read More
  16. FOR UPDATE

    Date2016.01.27 Category질의작성 By정만영 Views5989
    Read More
  17. 'Has been interrupted.' CUBRIDException 발생

    Date2016.01.07 Category운영관리 By주현 Views6582
    Read More
  18. 각 테이블 PK 유무 확인 쿼리문

    Date2016.01.01 Category질의작성 By엄기호 Views9002
    Read More
  19. ORACLE TRIGGER를 CUBRID TRIGGER로 변환하기

    Date2015.12.31 Category질의작성 By김창휘 Views6458
    Read More
  20. CUBRID DB에서 critical section 정보 출력하기

    Date2015.12.31 Category응용개발 By주현 Views4575
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 14 Next
/ 14

Contact Cubrid

대표전화 070-4077-2110 / 기술문의 070-4077-2113 / 영업문의 070-4077-2112 / Email. contact_at_cubrid.com
Contact Sales