Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

VBScript DatePart Function

VBScript DatePart Function


VBScript reference manual Complete VBScript Reference Manual


The DatePart function returns a specified part of a given date.

Syntax

DatePart(interval,date[,firstdayofweek[,firstweekofyear]])

Parameters Description
interval Required. The time interval to return.

The following values can be used:

  • yyyy - year
  • q - quarter
  • m - month
  • y - day of the year
  • d - day
  • w - day of the week
  • ww - week of the year
  • h - hour
  • n - minute
  • s - Seconds
  • | | date | Required. The date expression to be evaluated. | | firstdayofweek | Optional. Specifies the day of the week, that is, which day is the first day of the week.

    The following values can be used:

    | | firstweekofyear | Optional. Specifies the first week of the year.

    The following values can be used:

    |

    Example

    Example 1

    Get the month from a date:

    The example above produces the following output:

    2

    Try it »

    Example 2

    Get the month we are currently in:

    The example above produces the following output:

    document.write(DatePart("m",Now()))

    Try it »

    Example 3

    Get the hour:

    The example above produces the following output:

    document.write(DatePart("h",Now()))

    Try it »


    VBScript reference manual Complete VBScript Reference Manual