티스토리 뷰
출처 : http://blog.naver.com/stopi?Redirect=Log&logNo=70010518534
DATEDIFF
Returns the number of date and time boundaries crossed between two specified dates.
Syntax
DATEDIFF ( datepart , startdate , enddate )
Arguments
datepart
Is the parameter that specifies on which part of the date to calculate the difference. The table lists dateparts and abbreviations recognized by Microsoft® SQL Server™.
Datepart | Abbreviations |
---|---|
Year | yy, yyyy |
quarter | qq, q |
Month | mm, m |
dayofyear | dy, y |
Day | dd, d |
Week | wk, ww |
Hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |
startdate
Is the beginning date for the calculation. startdate is an expression that returns a datetime or smalldatetime value, or a character string in a date format.
Because smalldatetime is accurate only to the minute, when a smalldatetime value is used, seconds and milliseconds are always 0.
If you specify only the last two digits of the year, values less than or equal to the last two digits of the value of the two digit year cutoff configuration option are in the same century as the cutoff year. Values greater than the last two digits of the value of this option are in the century that precedes the cutoff year. For example, if the two digit year cutoff is 2049 (default), 49 is interpreted as 2049 and 2050 is interpreted as 1950. To avoid ambiguity, use four-digit years.
For more information about specifying time values, see
enddate
Is the ending date for the calculation. enddate is an expression that returns a datetime or smalldatetime value, or a character string in a date format.
Return Types
integer
Remarks
startdate is subtracted from enddate. If startdate is later than enddate, a negative value is returned.
DATEDIFF produces an error if the result is out of range for integer values. For milliseconds, the maximum number is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum number is 68 years.
The method of counting crossed boundaries such as minutes, seconds, and milliseconds makes the result given by DATEDIFF consistent across all data types. The result is a signed integer value equal to the number of datepart boundaries crossed between the first and second date. For example, the number of weeks between Sunday, January 4, and Sunday, January 11, is 1.
Examples
This example determines the difference in days between the current date and the publication date for titles in the pubs database.
USE pubs
GO
SELECT DATEDIFF(day, pubdate, getdate()) AS no_of_days
FROM titles
GO
============================================================================================
시간차를 구하고 싶었는데 h라고 주면 자꾸 에러가나서 옵션이 멀까 뒤져보다가 나와서 낼름 복사해왔다.
정답은 hh였어... 킁..
'Computer > Databases' 카테고리의 다른 글
[MSSQL] INDEX Create 와 Drop (2) | 2009.12.18 |
---|---|
[MSSQL] Constraint 때문에 Alter / Drop 실행이 안될때.. (0) | 2009.11.20 |
[MSSQL2005] Data Type Conversion Error (0) | 2009.10.13 |
[MSSQL2005] YYYYMMDDHHMISS형태의 날짜 String 을 Datetime으로 (0) | 2009.10.08 |
[MSSQL] REPLACE (0) | 2009.09.23 |
- Total
- Today
- Yesterday
- 새희망씨앗 피해자
- MySQL
- javascript
- 리터너블
- 기부사기
- 마라탕 #마라상궈 #마라탕재료 #쉽게만드는마라탕 #중딩입맛 #마라탕잡탕
- 부드러운맛
- 팸세일
- 나이지리아
- 홈택스
- 새희망씨앗
- UML
- 안드로이드
- 와코마리아팸세일
- 인도
- 사업자등록
- 기부피해
- 해외직구
- 와코마리아한남동
- 와코마리아
- 패밀리세일
- 6월 패밀리세일
- 단체소송
- 라고스
- java
- 한남동세일
- 와코마리아 스웨터
- VirtureBox
- eclipse
- 페밀리세일
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |