728x90

FormatDateTime(Date[, NamedFormat])

 

date

Required. Date expression to be formatted.

NamedFormat

Optional. Numeric value that indicates the date/time format used. If omitted, vbGeneralDate is used.


vbGeneralDate

0

Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed.

vbLongDate

1

Display a date using the long date format specified in your computer's regional settings.

vbShortDate

2

Display a date using the short date format specified in your computer's regional settings.

vbLongTime

3

Display a time using the time format specified in your computer's regional settings.

vbShortTime

4

Display a time using the 24-hour format (hh:mm).


Function GetCurrentDate


' FormatDateTime formats Date in long date.


GetCurrentDate = FormatDateTime(Date, 1)


End Function



Response.Write FormatDateTime(Now, 0) & "<br>" '2005-06-21 오후 2:56:46

Response.Write FormatDateTime(Now, 1) & "<br>" '2005년 6월 21일 화요일
Response.Write FormatDateTime(Now, 2) & "<br>" '2005-06-21
Response.Write FormatDateTime(Now, 3) & "<br>" '오후 2:56:46
Response.Write FormatDateTime(Now, 4) & "<br>" '14:56

728x90

'Developer > ASP (Active Server Page)' 카테고리의 다른 글

asp 내장함수  (0) 2008.08.07
IIS 6.0에서 ASP include file 에러 발생시 대처법  (0) 2007.12.27
FileSystemObject개체  (0) 2007.07.03
728x90

DECLARE @dt AS   DATETIME
SET @dt = '12/28/2006 16:32:14'

----------------------------------------------


예제1) CONVERT 이용한 기본 포맷 보기

CONVERT ( data_type [ ( length ) ] , expression [ , style ] )

----------------------------------------------

SELECT CONVERT(NVARCHAR, @dt, 100)

핑크 부분만 바꿔준 결과 보자.


100 --- Dec 28 2006  4:32PM
101 --- 12/28/2006

102 --- 2006.12.28

103 --- 28/12/2006

104 --- 28.12.2006

105 --- 28-12-2006

106 --- 28 Dec 2006

107 --- Dec 28, 2006

108 --- 16:32:14

109 --- Dec 28 2006  4:32:14:000PM
110 --- 12-28-2006
111 --- 2006/12/28
112 --- 20061228
113 --- 28 Dec 2006 16:32:14:000
114 --- 16:32:14:000

----------------------------------------------


예제2) DATEPART 이용한 기본 포맷 보기

DATEPART ( datepart , date )

* INT 값으로 결과가 나타난다.

----------------------------------------------

SELECT DATEPART(YEAR, @dt)

핑크 부분만 바꿔준 결과 보자.


YEAR (YY, YYYY) --- 2006

QUARTER (Q) --- 4 (분기)
MONTH (M, MM) --- 12

DAYOFYEAR (DY) --- 362 (일년중에 몇번째 날인지 알아볼때)

WEEK (WK, WW) --- 52 (몇번째 주인지 알아볼때)

DAY (D, DD)--- 28

WEEKDAY (DW) --- 5 (일주일에서 몇번째 날인지 알아볼때, 월요일 = 1, 화요일 = 2, ..., 일요일 = 7)

HOUR (HH) --- 16

MINUTE (MI, N)--- 32

SECOND (S, SS) --- 14

MILLISECOND (MS) --- 0


* ()안에는 대체할수 있는 약어들.

----------------------------------------------


예제3) LEFT / RIGHT / SUBSTRING 이용해서 나한테 필요한 부분만 콕 찝어 보기

LEFT / RIGHT / SUBSTRING 은 스트링 펑션이니까 예제 1 결과물을 이용하면 딱이겠죠. ^^

----------------------------------------------

SELECT CONVERT(NVARCHAR, @dt, 108)
결과)16:32:14


SELECT LEFT(CONVERT(NVARCHAR, @dt, 108), 5)  '왼쪽에서부터 5번째까지 보여주기.

결과)16:32



SELECT CONVERT(NVARCHAR, @dt, 100)

결과)Dec 31 2006  4:32PM


SELECT RIGHT(CONVERT(NVARCHAR, @dt, 100), 2)  '오른쪽에서부터 2번째까지 보여주기.

결과)PM


SELECT CONVERT(NVARCHAR, @dt, 106)

결과)28 Dec 2006

SELECT SUBSTRING(CONVERT(NVARCHAR, @dt, 106), 4, 3)  '왼쪽에서 4번째 글자부터 3글자 보여주기.

결과)Dec

----------------------------------------------

728x90

'Information' 카테고리의 다른 글

CD 케이스접기-A4  (0) 2007.03.25
웹2.0 관련 기사  (0) 2007.03.21
Ajax Prototype.js - 프로토타입 완전분석  (0) 2007.03.20

+ Recent posts