ฟังก์ชันVBScript DatePart
❮ การอ้างอิง VBScript ที่สมบูรณ์ฟังก์ชัน DatePart ส่งคืนส่วนที่ระบุของวันที่ที่กำหนด
ไวยากรณ์
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:
|
ตัวอย่าง
ตัวอย่าง 1
รับเดือนจากวันที่:
<%
d=CDate("2010-02-16")
response.write(DatePart("m",d))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
2
ตัวอย่าง 2
รับเดือนที่เราอยู่:
<%
response.write(DatePart("m",Now()))
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
1
ตัวอย่างที่ 3
รับชั่วโมง:
<%
response.write(DatePart("h",Now())
%>
ผลลัพธ์ของโค้ดด้านบนจะเป็น:
13
❮ การอ้างอิง VBScript ที่สมบูรณ์