Background Image
조회 수 8110 추천 수 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. CUBRID 와 DBCP의 관계

    Date2016.12.14 Category응용개발 By엄기호 Views5204
    Read More
  2. 입력된 년월 또는 두개의 날짜을 이용하여 달력 및 주차 구하기

    Date2016.08.10 Category질의작성 By성진 Views8200
    Read More
  3. 큐브리드 포트 정리

    Date2016.07.05 Category운영관리 By정만영 Views8587
    Read More
  4. 큐브리드 마스터 소켓 디렉토리 변경방법

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    Date2016.01.07 Category운영관리 By주현 Views8507
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 15 Next
/ 15

Contact Cubrid

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