날짜, 시간 함수 (Date and Time Functions)

canyi·2023년 6월 4일
0

MSSQL

목록 보기
17/21

SELECT 
GETDATE() AS my_time,
GETUTCDATE() AS utc_time;

  • 한국은 GMT +9시간을 현지 시간으로 이용

DATEPART( )

weekday : 1(월요일), 7(토요일)

CONVERT( )

SELECT 
	OrderDate,
	CONVERT(varchar(10), OrderDate,120) AS o_date1,
	CONVERT(varchar(10), OrderDate,110) AS o_date2
FROM
SalesOrder;

DATEDIFF( )

SELECT 
	DATEDIFF(day, '2000-01-01', '2000-01-03') AS d_days,
	DATEDIFF(hour, '12:00:00', '15:00:00') AS d_hours,
	DATEDIFF(week, '2000-01-01', '2000-12-31') AS d_weeks;

배송소요 날짜 기간 조회

DATEADD( )

SELECT
DATEADD(day, 100, '2000-01-01') AS add_days,
DATEADD(hour, 5, '12:00:00') AS add_hours,
DATEADD(week, 10, '2000-01-01') AS add_weeks;

Point

profile
백엔드 개발 정리

0개의 댓글