Skip to content

Commit d709fb4

Browse files
soyeric128BohuTANG
authored andcommitted
Update 20-data-type-time-date-types.md
1 parent 4fb53b9 commit d709fb4

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

docs/en/sql-reference/00-sql-reference/10-data-types/20-data-type-time-date-types.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Basic Date and Time data type.
55

66
import FunctionDescription from '@site/src/components/FunctionDescription';
77

8-
<FunctionDescription description="Introduced or updated: v1.2.575"/>
8+
<FunctionDescription description="Introduced or updated: v1.2.648"/>
99

1010
## Date and Time Data Types
1111

@@ -198,6 +198,36 @@ SELECT to_datetime('2024-03-10 02:01:00');
198198
└────────────────────────────────────┘
199199
```
200200

201+
## Handling Invalid Values
202+
203+
Databend automatically converts invalid Date or Timestamp values to their minimum valid equivalents, `1000-01-01` for dates and `1000-01-01 00:00:00` for timestamps, ensuring consistency when working with out-of-range or incorrectly formatted dates and timestamps.
204+
205+
Examples:
206+
207+
```sql
208+
-- Attempts to add one day to the maximum date, exceeding the valid range.
209+
-- Result: Returns DateMIN (1000-01-01) instead of an error.
210+
SELECT ADD_DAYS(TO_DATE('9999-12-31'), 1);
211+
212+
┌────────────────────────────────────┐
213+
│ add_days(to_date('9999-12-31'), 1) │
214+
├────────────────────────────────────┤
215+
1000-01-01
216+
└────────────────────────────────────┘
217+
```
218+
219+
```sql
220+
-- Attempts to subtract one minute from the minimum date, which would be invalid.
221+
-- Result: Returns DateMIN (1000-01-01 00:00:00), ensuring stability in results.
222+
SELECT SUBTRACT_MINUTES(TO_DATE('1000-01-01'), 1);
223+
224+
┌────────────────────────────────────────────┐
225+
│ subtract_minutes(to_date('1000-01-01'), 1) │
226+
├────────────────────────────────────────────┤
227+
1000-01-01 00:00:00
228+
└────────────────────────────────────────────┘
229+
```
230+
201231
## Formatting Date and Time
202232

203233
In Databend, certain date and time functions like [TO_DATE](../../20-sql-functions/05-datetime-functions/to-date.md) and [TO_TIMESTAMP](../../20-sql-functions/05-datetime-functions/to-timestamp.md) require you to specify the desired format for date and time values. To handle date and time formatting, Databend makes use of the chrono::format::strftime module, which is a standard module provided by the chrono library in Rust. This module enables precise control over the formatting of dates and times. The following content is excerpted from [https://docs.rs/chrono/latest/chrono/format/strftime/index.html](https://docs.rs/chrono/latest/chrono/format/strftime/index.html):

0 commit comments

Comments
 (0)