Text Documents (Writer)
HTML Documents (Writer Web)
Spreadsheets (Calc)
Presentations (Impress)
Drawings (Draw)
Database Functionality (Base)
Formulae (Math)
Charts and Diagrams
Macros and Scripting
Office Installation
Common Help Topics
OneOffice Logo

DatePart Function

The DatePart function returns a specified part of a date.

Syntax:


DatePart (interval As String, date As Date [, firstDayOfWeek As Integer [, firstWeekOfYear As Integer]]) As Long

Return value:

The extracted part for the given date.

Parameters:

interval - A string expression from the following table, specifying the date interval.

interval (string value) Explanation
yyyy Year
q Quarter
m Month
y Day of year
w Weekday
ww Week of year
d Day
h Hour
n Minute
s Second

date - The date from which the result is calculated.

Date literals allow to specify unambiguous date variables that are independent from the current language. Literals are enclosed between hash signs #. Possible formats are:

  • #yyyy-mm-dd#
  • #mm/dd/yyyy#

firstdayofweek: An optional parameter that specifies the starting day of a week.

firstdayofweek value Explanation
0 Use system default value
1 Sunday (default)
2 Monday
3 Tuesday
4 Wednesday
5 Thursday
6 Friday
7 Saturday

firstweekofyear: An optional parameter that specifies the starting week of a year.

firstweekofyear value Explanation
0 Use system default value
1 Week 1 is the week that includes 1st January (default)
2 Week 1 is the first week containing four or more days of that year
3 Week 1 is the first week containing only days of the new year

Example:


Sub example-datepart
    MsgBox DatePart("ww", #12/31/2005#)
    MsgBox DatePart(date:=#1999-12-30#, interval:="q")
End Sub