[]
        
(Showing Draft Content)

DATEPART

This function returns the Date object for a particular date, specified by the year, month, and day.

Syntax

DATEPART ( date_value, format_string, [week_num_type] )

Arguments

Argument

Description

date_value

(Required) The date value.

format_string

(Required) The format string of the date.

[week_num_type]

(Optional) The same as the second argument of WEEKNUM.

Remarks

You can use this function to group the field.


The following table shows the different format strings that can be used for the DATEPART formula:

Format

Result

Description

yyyQ

20214

Numeric: 1 digit (Quarter number/name)

yyyQQ

202104

Numeric: 2 digits + zero pad

yyyyQQQ

2021Q4

Abbreviated

yyyy QQQQ

2021 4th quarter

Wide

YYYY w

2021 8

Numeric: minimum digits Week of Year (numeric).

When used in a pattern with year, use ‘Y’ for the year field.

YYYY ww

2021 08

Numeric: 2 digits, zero pad if needed.

MM-yyyy

09-2021

Provide partial date formatter in cell formatting.

Data Types

Accept string data. Returns a Date object.

Examples

The following sample code shows the basic usage of the DATEPART function.

sheet.groupBy([
    {
        caption: "Company Name", field: "Customers.CompanyName", width: 160,
    },
    {
        caption: "Year Quarter", field: `=DATEPART([@OrderDate],"yyyyQQQ")`, width: 160,
    }
]);