달력

09

« 2018/09 »

  •  
  •  
  •  
  •  
  •  
  •  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  •  
  •  
  •  
  •  
  •  
  •  
2017.06.06 12:29

MSSQL - Date Function 날짜함수 예제 Tech/MSSQL2017.06.06 12:29

MSSQL - Date Function 날짜함수 예제 


SELECT GETDATE() as Now_DateTime
2017-06-06 11:26:54.830

SELECT CONVERT(Date, GETDATE()) as Now_Date
2017-06-06

SELECT CONVERT(nvarchar(10), GETDATE(), 120) as Now_Date
2017-06-06

SELECT DATEDIFF(HOUR, '2017-06-01', GETDATE()) as DiffHour 
131

SELECT DATEDIFF(HOUR, '2017-06-01 00:00:00.000', GETDATE()) as DiffHour
131

-- 특정 날짜로부터 오늘까지의 차이 (일)
SELECT DATEDIFF(DAY, '2017-06-01', GETDATE()) as DiffDay
5

-- 특정 날짜로부터 오늘까지의 차이 (일)
SELECT DATEDIFF(DAY, '2017-06-01 00:00:00.000', GETDATE()) as DiffDay
5

-- 어제 날짜 구하기 
SELECT dateadd(d, -1, getdate()) 
2017-06-05

-- 보기좋게 날짜 변경하기 
SELECT 
   ISNULL(
      CONVERT(nvarchar(10), GETDATE(), 120)+' '+CONVERT(nvarchar(8), GETDATE(), 108)
    , '0000-00-00 00:00:00') 
2017-06-06 11:26:54
Posted by 멋지다마라송


티스토리 툴바