> Tommy Note :: [SQL] 시간 관련 쿼리

달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2015. 12. 28. 14:57

[SQL] 시간 관련 쿼리 SQL2015. 12. 28. 14:57

1. 현재 시간에서 10초를 빼기 위한 방법

select getdate(), getdate() - (CAST(1 AS FLOAT) / 24 / 60 / 60 * 10)


2. 현재 시간에서 10초를 더하기

select getdate(), convert(varchar(30), dateadd(s, 10, getdate()), 121)


3. 조회 조건이 날짜와 시간이 아니라 특정 시간에 대한 내용 찾기

A. 조건을 시간 단위로 찾기 

select * from Termination_Call_Detail where datename(hh, DateTime) between '10' and '11'

또는

select * from Termination_Call_Detail where datepart(hh, DateTime) between '10' and '11'

B. 조건을 분 단위로 찾기

select * from Termination_Call_Detail where datename(mi, DateTime) between '00' and '30'

또는

select * from Termination_Call_Detail where datepart(mi, DateTime) between '00' and '30'

C. 매주 월요일 10시 부터 11시까지 조회

select * from Termination_Call_Detail 

where datename(WEEKDAY, DateTime) = '월요일' and datename(HOUR, DateTime) between '10' and '11'

또는

select * from Termination_Call_Detail 

where datepart(WEEKDAY, DateTime) = '2' and datename(HOUR, DateTime) between '10' and '11' 

-- WEEKDAY 결과 1:일,2:월,3:화,4:수,5:목,6:금,7:토






:
Posted by 부다투더리