--- title: "WEEKOF(A,B)" slug: "engineeringdatefunction2-19" updated: 2021-10-15T17:23:21Z published: 2021-10-15T17:23:21Z canonical: "docs.datajet.app/engineeringdatefunction2-19" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.datajet.app/llms.txt > Use this file to discover all available pages before exploring further. # WEEKOF(A,B) ## Date Transform: WEEKOF(A,B) ## Groups Date B into weekly segments, where first week begins on Date A ## Purpose Use this function to: - Group observations into weekly segments, starting on a fixed date - Segment data for use in a time-series report, where the reporting interval is in weeks - Calculate "Week Commencing" for a date field (W/C) ## Return Value | Property | Value | | --- | --- | | **FieldType** | Date | | **FieldSize** | | | **DataType** | Discrete | | **DataSize** | Short | ```shell Example Return Value: 2019-01-01, 2019-01-08... Where values are always 7 days apart ``` ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/WEEKOF_Sample.PNG) ## Parameters | Parameter | JSON | Description | | --- | --- | --- | | **Table** | “targetTable”: “MyTableName” | The target table on which the new field will be created | | **Filter** | “dataset”: {DataSet_JSON} | Optional. If a filter is applied, records not in the filter Recordset will be returned as null. | | **DateTimeFunction** | “p1”: “WEEKOF(A,B)” | WEEKOF(A,B) | | **A** | “p2”: “DateTimeFieldName” “p2”: “DateFieldName” “p2”: “#YYYY-MM-DD HH:MM:SS” “p2”: “#YYYY-MM-DD” | Required. The date which provides the first value in the week commencing series *Supports:* - **DataType:** Discrete / Continuous - **Field Type:** Date, DateTime - **Fixed Value:** #YYYY-MM-DD, e.g. #2021-04-05 - **Fixed Value:** #YYYY-MM-DD HH:MM:SS, e.g. #2021-04-05 11:01:08 If A is a date field, the value in A will be used as the first date in the series, and WEEKOF(A,B) will be the closest preceeding week that is a multiple of 7 days after A. For example: If A is 2019-01-01, and B is 2019-01-06, WEEKOF(A,B) will be 2019-01-01 If A is 2019-01-01, and B is 2019-01-09, WEEKOF(A,B) will be 2019-01-08 If A is 2019-02-08, and B is 2019-02-06, WEEKOF(A,B) will be 2019-02-01 If A is 2019-02-09, and B is 2019-02-06, WEEKOF(A,B) will be 2019-02-02 | | **B** | “p3”: “DateTimeFieldName” “p3”: “DateFieldName” “p3”: “#YYYY-MM-DD HH:MM:SS” “p3”: “#YYYY-MM-DD” | Required. The date to sort into Weekly segments *Supports:* - **DataType:** Discrete / Continuous - **Field Type:** Date, DateTime - **Fixed Value:** #YYYY-MM-DD, e.g. #2021-04-05 - **Fixed Value:** #YYYY-MM-DD HH:MM:SS, e.g. #2021-04-05 11:01:08 | ## JSON Sample ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/WEEKOF_JSON.PNG) ## Usage Notes Use this function to calculate the date of the beginning of the week for an event or observation. To specify the day on which the week commences, make sure that parameter A falls on the desired weekday. See Also: - [WEEKDAY(A)](/v1/docs/engineeringdatefunction2-18) - Week day as integer - [SWEEKDAY(A)](/v1/docs/engineeringdatefunction2-17) - Weekday as string - [WOY(A)](/v1/docs/engineeringdatefunction2-20) - Week of year ## Example | Example | Details | | --- | --- | | **Description** | Group into weeks, where first week begins on #201-01-01 | | **Input** | - Table: = [transactions] - Function: = DateTransform - **DateTimeFunction: = WEEKOF(A,B)** - A:= #2019-01-01 - B: = [transactions].[date] - Name: =WeekofDate | | **Sample** | ![](https://cdn.document360.io/73b6469b-c1e4-47e9-aa65-986c8ebd17ca/Images/Documentation/WEEKOF_Example.PNG) |