ASP 날짜 시간관련 함수


ASP 날짜 시간관련 함수


1. Date - 현재날짜 구하기

Now - 현재 날짜와 시간 구하기

예제 1) 오늘 날짜 출력

1
2
Response.Write("오늘 날짜" : "&Date)
결과 : 오늘날짜 : 2011-06-26<- 오늘의 날짜를 현제형식으로 리턴

예제 2) 2011/06/26 형식으로 출력

1
2
3
4
5
6
7
8
9
10
11
12
13
14

Function putZero(obj)
If CInt(obj)<10 Then
putZero = "0"&obj
Else
putZero = obj
End If
End Function


Response.Write Year(Date)&"-"&Month(Date)&"-"&Day(Date)
Response.Write ""&putZero(Hour(Now()))&":"&putZero(Minute(Now()))&":"
&putZero(Second(Now()))
결과 : 2011-06-26 12:39:25

2. DateSerial - 특정 날짜 계산해서 날짜값 구하기

예제 1) 오늘로부터 2달전 마지막 날을 구하기 오늘이 만약 “2011-06”27”이라면

1
2
SomeDate = DateSerial(Year(Date), Month(Date) - 1, 1 - 1)
Response.Write "SomeDay 는 2011-05-31 이 찍힘"&DateSerial

3 . DatePart - 날짜의 특정 부분을 표시할 수 있도록 해준다.

1
형식 : DatePart(interval, date[,firstdayofweek[,firstdayofyear]])

예제1) 원하는 날짜의 “월”만 표시, 오늘이 만약 “2011-06”27”이라면

1
Response.Write "6월달이라는 표시가 뜬다 "&DatePart('m',DateSerial(2011,6,27))

4 . DateAdd - 날짜를 더하는 함수

1
형식: DateAdd(interval, number, date)

예제1) 오늘로부터 정확히 1년전 그 주의 요일을 구하기, 오늘이 만약 “2011-06”27”이라면

1
Response.Write "2010-06-27 일의 'w' 그주의 요일을 구한다 "&DatePart("w", DateAdd("y", -1, Date))

5.DateDiff - 두 널짜의 날 수를 구하기

예제1) 현재 날짜와 SomeDate 사이의 몇주가 있는지를 구하기

1
DateDiff("w", Now, SomeDate)

예제2) 현재 날짜와 SomeDate 사이에 몇 일이 있는지를 구하기

1
2
3
4
Dim SomeDate: SomeDate = SDate("2011-06-26")
오늘이 만약 "2011-06"27"이라면
strDate = DateDiff("d",Date,SomeDate)
Response.Write "strDate는 1을 리턴한다 'd'Day 의 날수 계산 "&strDate

6.weekday, weekdayname - 요일명 확인

예제)

1
2
3
4
currdate = Now()
currid = weekday(currdate)
currname = weekdayname(currid)
response.Write " today is"&currname

7.MonthName - 월명확인

예제)

1
2
currid = Month(Currdate)
Response.Write MonthName(currid)

8. DateValue - 문자열을 Date 형 날짜로 반환

예제)

1
2
date = DateValue("december 25, 2001"))
Response.Write "결과값은 2001-12-25로 출력 "&date
Share