mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
add doc
fix test fix name style fix
This commit is contained in:
parent
f0b423e928
commit
767bc7a905
@ -503,3 +503,34 @@ Supported modifiers for Format:
|
|||||||
| %% | a % sign | % |
|
| %% | a % sign | % |
|
||||||
|
|
||||||
[Original article](https://clickhouse.tech/docs/en/query_language/functions/date_time_functions/) <!--hide-->
|
[Original article](https://clickhouse.tech/docs/en/query_language/functions/date_time_functions/) <!--hide-->
|
||||||
|
|
||||||
|
## FROM_UNIXTIME
|
||||||
|
|
||||||
|
When there is only single argument of integer type, it act in the same way as `toDateTime` and return [DateTime](../../sql-reference/data-types/datetime.md).
|
||||||
|
type.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT FROM_UNIXTIME(423543535)
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
┌─FROM_UNIXTIME(423543535)─┐
|
||||||
|
│ 1983-06-04 10:58:55 │
|
||||||
|
└──────────────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
When there are two arguments, first is integer or DateTime, second is constant format string, it act in the same way as `formatDateTime` and return `String` type.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```sql
|
||||||
|
SELECT FROM_UNIXTIME(1234334543, '%Y-%m-%d %R:%S') AS DateTime
|
||||||
|
```
|
||||||
|
|
||||||
|
```text
|
||||||
|
┌─DateTime────────────┐
|
||||||
|
│ 2009-02-11 14:42:23 │
|
||||||
|
└─────────────────────┘
|
||||||
|
```
|
||||||
|
@ -415,7 +415,7 @@ public:
|
|||||||
size_t result_size = pattern_to_fill.size();
|
size_t result_size = pattern_to_fill.size();
|
||||||
|
|
||||||
const DateLUTImpl * time_zone_tmp = nullptr;
|
const DateLUTImpl * time_zone_tmp = nullptr;
|
||||||
if (castType(block.getByPosition(arguments[0]).type.get(), [&](const auto & type) { return true; }))
|
if (castType(block.getByPosition(arguments[0]).type.get(), [&]([[maybe_unused]] const auto & type) { return true; }))
|
||||||
{
|
{
|
||||||
time_zone_tmp = &extractTimeZoneFromFunctionArguments(block, arguments, 2, 0);
|
time_zone_tmp = &extractTimeZoneFromFunctionArguments(block, arguments, 2, 0);
|
||||||
}
|
}
|
||||||
@ -706,13 +706,13 @@ struct NameFormatDateTime
|
|||||||
static constexpr auto name = "formatDateTime";
|
static constexpr auto name = "formatDateTime";
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NameFROM_UNIXTIME
|
struct NameFromUnixTime
|
||||||
{
|
{
|
||||||
static constexpr auto name = "FROM_UNIXTIME";
|
static constexpr auto name = "FROM_UNIXTIME";
|
||||||
};
|
};
|
||||||
|
|
||||||
using FunctionFormatDateTime = FunctionFormatDateTimeImpl<NameFormatDateTime, false>;
|
using FunctionFormatDateTime = FunctionFormatDateTimeImpl<NameFormatDateTime, false>;
|
||||||
using FunctionFROM_UNIXTIME = FunctionFormatDateTimeImpl<NameFROM_UNIXTIME, true>;
|
using FunctionFROM_UNIXTIME = FunctionFormatDateTimeImpl<NameFromUnixTime, true>;
|
||||||
|
|
||||||
void registerFunctionFormatDateTime(FunctionFactory & factory)
|
void registerFunctionFormatDateTime(FunctionFactory & factory)
|
||||||
{
|
{
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
1970-01-01 08:02:03
|
1970-01-01 00:02:03
|
||||||
1970-01-01 11:25:45
|
1973-11-29 21:33:09
|
||||||
1970-03-17 01:44:37
|
2038-07-12 01:15:36
|
||||||
19
|
|
||||||
19
|
19
|
||||||
|
11
|
||||||
1970-01-15
|
1970-01-15
|
||||||
1970-01-15 14:52:36
|
1970-01-15 06:52:36
|
||||||
20
|
20
|
||||||
02
|
02
|
||||||
01/02/18
|
01/02/18
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
SELECT FROM_UNIXTIME(123);
|
SELECT formatDateTime(FROM_UNIXTIME(123), '%Y-%m-%d %R:%S', 'UTC');
|
||||||
SELECT FROM_UNIXTIME(12345);
|
SELECT formatDateTime(FROM_UNIXTIME(123456789), '%Y-%m-%d %R:%S', 'UTC');
|
||||||
SELECT FROM_UNIXTIME(6457477);
|
SELECT formatDateTime(FROM_UNIXTIME(6457477432), '%Y-%m-%d %R:%S', 'UTC');
|
||||||
SELECT FROM_UNIXTIME(5345345, '%C');
|
SELECT FROM_UNIXTIME(5345345, '%C', 'UTC');
|
||||||
SELECT FROM_UNIXTIME(645123, '%H');
|
SELECT FROM_UNIXTIME(645123, '%H', 'UTC');
|
||||||
SELECT FROM_UNIXTIME(1232456, '%Y-%m-%d');
|
SELECT FROM_UNIXTIME(1232456, '%Y-%m-%d', 'UTC');
|
||||||
SELECT FROM_UNIXTIME(1234356, '%Y-%m-%d %R:%S');
|
SELECT FROM_UNIXTIME(1234356, '%Y-%m-%d %R:%S', 'UTC');
|
||||||
SELECT FROM_UNIXTIME(toDateTime('2018-01-02 22:33:44'), '%C');
|
SELECT FROM_UNIXTIME(toDateTime('2018-01-02 22:33:44'), '%C');
|
||||||
SELECT FROM_UNIXTIME(toDateTime('2018-01-02 22:33:44'), '%d');
|
SELECT FROM_UNIXTIME(toDateTime('2018-01-02 22:33:44'), '%d');
|
||||||
SELECT FROM_UNIXTIME(toDateTime('2018-01-02 22:33:44'), '%D');
|
SELECT FROM_UNIXTIME(toDateTime('2018-01-02 22:33:44'), '%D');
|
||||||
|
Loading…
Reference in New Issue
Block a user