# Last Day in the Week, Month, Quarter, or Year

Returns the date of the last day in the specified week, month, quarter, or year.

## Usage

Use these functions in a `foreach()` statement. You cannot use them in `group by`, `order by`, or `filter` statements.

Use the functions whose names begin with `week`, `month`, `quarter`, and `year` with standard calendar year dates. Use the functions whose names begin with `fiscal` with fiscal year dates.

:::note
You can't use fiscal date functions in recipes and dataflow transformations.
:::

## week_last_day(date)

Returns the date of the last day of the week for the specified date.

:::note
This function always counts the `firstDayOfWeek` as 0 (Sunday). It overrides the `firstDayOfWeek` parameter for `sfdcDigestTransformation` and CSV uploads.
:::

```nolang
q = foreach q generate week_last_day(toDate('CloseDate_sec_epoch')) as 'Week Last Day';
```

## fiscal_week_last_day(date)

Returns the fiscal date of the last day of the week for the specified date.

:::note
This function respects the `firstDayOfWeek` parameter for `sfdcDigestTransformation` and CSV uploads. The default value is 0 (Sunday).
:::

```nolang
q = foreach q generate fiscal_week_last_day(toDate('CloseDate_sec_epoch')) as 'Fiscal Week Last Day';
```

## month_last_day(date)

Returns the date of the last day of the month for the specified date.

```nolang
q = foreach q generate month_last_day(toDate('CloseDate_sec_epoch')) as 'Month Last Day';
```

## fiscal_month_last_day(date)

Returns the fiscal date of the last day of the month for the specified date.

```nolang
q = foreach q generate fiscal_month_last_day(toDate('CloseDate_sec_epoch')) as 'Fiscal Month Last Day';
```

## quarter_last_day(date)

Returns the date of the last day of the quarter for the specified date.

```nolang
q = foreach q generate quarter_last_day(toDate('CloseDate_sec_epoch')) as 'Quarter Last Day';
```

## fiscal_quarter_last_day(date)

Returns the fiscal date of the last day of the quarter for the specified date.

```nolang
q = foreach q generate fiscal_quarter_last_day(toDate('CloseDate_sec_epoch')) as 'Fiscal Quarter Last Day';
```

## year_last_day(date)

Returns the date of the last day of the year for the specified date.

```nolang
q = foreach q generate year_last_day(toDate('CloseDate_sec_epoch')) as 'Year Last Day';
```

:::note
This function always returns 31st December. You can use it to find the number of days to the year end.
:::

## fiscal_year_last_day(date)

Returns the fiscal date of the last day of the year for the specified date.

```nolang
q = foreach q generate fiscal_year_last_day(toDate('CloseDate_sec_epoch')) as 'Fiscal Year Last Day';
```

**See Also**

- [Date Formats and Fiscal Dates for Source Data](https://help.salesforce.com/s/articleView?id=bi_integrate_date_formats_and_fiscal_dates.htm)
