Hàm DatePart trong VBScript
❮ Toàn bộ tài liệu tham khảo VBScriptHàm DatePart trả về phần được chỉ định của một ngày nhất định.
Cú pháp
DatePart(interval,date[,firstdayofweek[,firstweekofyear]])
Parameter | Description |
---|---|
interval | Required. The interval of time to return. Can take the following values:
|
date | Required. Date expression to evaluate |
firstdayofweek | Optional. Specifies the day of the week. Can take the following values:
|
firstweekofyear | Optional. Specifies the first week of the year. Can take the following values:
|
Các ví dụ
ví dụ 1
Lấy tháng từ một ngày:
<%
d=CDate("2010-02-16")
response.write(DatePart("m",d))
%>
Đầu ra của đoạn mã trên sẽ là:
2
Ví dụ 2
Lấy tháng chúng ta đang ở:
<%
response.write(DatePart("m",Now()))
%>
Đầu ra của đoạn mã trên sẽ là:
1
Ví dụ 3
Nhận giờ:
<%
response.write(DatePart("h",Now())
%>
Đầu ra của đoạn mã trên sẽ là:
8
❮ Toàn bộ tài liệu tham khảo VBScript