VBScript DatePart function
DatePart function returns a specified part of a given date.
grammar
DatePart(interval,date[,firstdayofweek[,firstweekofyear]])
参数 | 描述 |
---|---|
interval | 必需。要返回的时间间隔。 可采用下面的值:
|
date | 必需。需计算的日期表达式。 |
firstdayofweek | 可选。规定一周的日数,即当周的第几天。 可采用下面的值:
|
firstweekofyear | 可选。规定一年中的第一周。 可采用下面的值:
|
Examples
Example 1
Get month from a date:
<script type="text/vbscript">
d=CDate("2010-02-16")
document.write(DatePart("m",d))
</script>
d=CDate("2010-02-16")
document.write(DatePart("m",d))
</script>
Examples of the above output:
2
try it"
Example 2
We are at the month get:
<script type="text/vbscript">
document.write(DatePart("m",Now()))
</script>
document.write(DatePart("m",Now()))
</script>
Examples of the above output:
document.write(DatePart("m",Now()))
try it"
Example 3
Get hours:
<script type="text/vbscript">
document.write(DatePart("h",Now())
</script>
document.write(DatePart("h",Now())
</script>
Examples of the above output:
document.write(DatePart("h",Now()))
try it"
Complete VBScript Reference