> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# days_sub

> Subtracts specified days from a date or datetime to get a new datetime.

Subtracts specified days from a date or datetime to get a new datetime.

## Syntax

```Haskell theme={null}
DATETIME days_sub(DATETIME|DATE d, INT n);
```

## Parameters

`d`: the date or datetime expression.

`n`: the number of days to subtract from the `d`.

## Return value

Returns a value of the datetime type, NULL is returned if any parameter is NULL or invalid.

NULL is returned if the result exceeds the range \[0000-01-01 00:00:00, 9999-12-31 00:00:00].

## Examples

```Plain Text theme={null}
SELECT DAYS_SUB('2022-12-20 12:00:00', 10);
+--------------------------------------------------+
| days_sub('2022-12-20 12:00:00', INTERVAL 10 DAY) |
+--------------------------------------------------+
| 2022-12-10 12:00:00                              |
+--------------------------------------------------+

SELECT DAYS_SUB('2022-12-20 12:00:00', -10);
+---------------------------------------------------+
| days_sub('2022-12-20 12:00:00', INTERVAL -10 DAY) |
+---------------------------------------------------+
| 2022-12-30 12:00:00                               |
+---------------------------------------------------+

SELECT DAYS_SUB('2022-12-20 12:00:00', 738874);
+------------------------------------------------------+
| days_sub('2022-12-20 12:00:00', INTERVAL 738874 DAY) |
+------------------------------------------------------+
| 0000-01-01 12:00:00                                  |
+------------------------------------------------------+

SELECT DAYS_SUB('2022-12-20 12:00:00', 738875);
+------------------------------------------------------+
| days_sub('2022-12-20 12:00:00', INTERVAL 738875 DAY) |
+------------------------------------------------------+
| NULL                                                 |
+------------------------------------------------------+

SELECT DAYS_SUB('2022-12-20 12:00:00', -2913550);
+--------------------------------------------------------+
| days_sub('2022-12-20 12:00:00', INTERVAL -2913550 DAY) |
+--------------------------------------------------------+
| 9999-12-31 12:00:00                                    |
+--------------------------------------------------------+

SELECT DAYS_SUB('2022-12-20 12:00:00', -2913551);
+--------------------------------------------------------+
| days_sub('2022-12-20 12:00:00', INTERVAL -2913551 DAY) |
+--------------------------------------------------------+
| NULL                                                   |
+--------------------------------------------------------+
```

## keywords

DAY,day


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.