You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/sql-reference/20-sql-functions/05-datetime-functions/to-timestamp.md
+42-6
Original file line number
Diff line number
Diff line change
@@ -3,33 +3,47 @@ title: TO_TIMESTAMP
3
3
---
4
4
import FunctionDescription from '@site/src/components/FunctionDescription';
5
5
6
-
<FunctionDescriptiondescription="Introduced or updated: v1.2.575"/>
6
+
<FunctionDescriptiondescription="Introduced or updated: v1.2.664"/>
7
7
8
8
Converts an expression to a date with time.
9
9
10
10
See also: [TO_DATE](to-date)
11
11
12
12
## Syntax
13
13
14
+
This function supports multiple overloads, covering the following use cases:
15
+
14
16
```sql
15
17
-- Convert a string or integer to a timestamp
16
18
TO_TIMESTAMP(<expr>)
17
19
```
18
20
19
-
If given an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date format string, the function extracts a date from the string; If given is an integer, the function interprets the integer as the number of seconds, milliseconds, or microseconds before (for a negative number) or after (for a positive number) the Unix epoch (midnight on January 1, 1970):
21
+
If given an [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date format string, the function extracts a date from the string; If given is an integer, the function interprets the integer as the number of seconds, milliseconds, or microseconds before (for a negative number) or after (for a positive number) the Unix epoch (midnight on January 1, 1970), depending on the absolute value of `x`:
-- Convert a string to a timestamp using the given pattern
29
31
TO_TIMESTAMP(<expr>, <pattern>)
30
32
```
31
33
32
-
If given two arguments, the function converts the first string to a timestamp based on the pattern specified in the second string. To specify the pattern, use specifiers. The specifiers allow you to define the desired format for date and time values. For a comprehensive list of supported specifiers, see [Formatting Date and Time](../../00-sql-reference/10-data-types/20-data-type-time-date-types.md#formatting-date-and-time).
34
+
The function converts the first string to a timestamp based on the pattern specified in the second string. To specify the pattern, use specifiers. The specifiers allow you to define the desired format for date and time values. For a comprehensive list of supported specifiers, see [Formatting Date and Time](../../00-sql-reference/10-data-types/20-data-type-time-date-types.md#formatting-date-and-time).
35
+
36
+
37
+
```sql
38
+
-- Convert an integer to a timestamp based on the specified scale
39
+
TO_TIMESTAMP(<int>, <scale>)
40
+
```
41
+
42
+
The function converts an integer value to a timestamp, interpreting the integer as the number of seconds (or fractional seconds, based on the specified scale) since the Unix epoch (midnight on January 1, 1970). The scale defines the precision of the fractional seconds and supports values from 0 to 6. For example:
43
+
44
+
-`scale = 0`: Interprets the integer as seconds.
45
+
-`scale = 1`: Interprets the integer as tenths of a second.
46
+
-`scale = 6`: Interprets the integer as microseconds.
0 commit comments