Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example of time type #2489

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions docs-2.0/3.ngql-guide/3.data-types/4.date-and-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,18 @@ nebula> RETURN timestamp(datetime("2022-08-29T07:53:10.939000"));
nebula> INSERT VERTEX date1(p1, p2, p3) VALUES "test1":(date("2021-03-17"), time("17:53:59"), datetime("2017-03-04T22:30:40.003000[Asia/Shanghai]"));
```

3. 获取`test1`的属性`p1`的月份。
3. 查询`test1`的属性`p1`是否为`2021-03-17`。

```ngql
nebula> MATCH (v:date1) RETURN v.date1.p1 == date("2021-03-17");
+----------------------------------+
| (v.date1.p1==date("2021-03-17")) |
+----------------------------------+
| true |
+----------------------------------+
```

4. 获取`test1`的属性`p1`的月份。

```ngql
nebula> CREATE TAG INDEX IF NOT EXISTS date1_index ON date1(p1);
Expand All @@ -189,13 +200,26 @@ nebula> RETURN timestamp(datetime("2022-08-29T07:53:10.939000"));
+------------------+
```

4. 创建 Tag,名称为`school`,包含`TIMESTAMP`类型。
5. 查找 Tag `date1`中属性`p3`小于`2023-01-01T00:00:00.000000`的值。

```ngql
nebula> MATCH (v:date1) \
WHERE v.date1.p3 < datetime("2023-01-01T00:00:00.000000") \
RETURN v.date1.p3;
+----------------------------+
| v.date1.p3 |
+----------------------------+
| 2017-03-04T14:30:40.003000 |
+----------------------------+
```

6. 创建 Tag,名称为`school`,包含`TIMESTAMP`类型。

```ngql
nebula> CREATE TAG IF NOT EXISTS school(name string , found_time timestamp);
```

5. 插入点,名称为`DUT`,存储时间为`"1988-03-01T08:00:00"`。
7. 插入点,名称为`DUT`,存储时间为`"1988-03-01T08:00:00"`。

```ngql
# 时间戳形式插入,1988-03-01T08:00:00 对应的时间戳为 573177600,转换为 UTC 时间为 573206400。
Expand All @@ -205,7 +229,7 @@ nebula> RETURN timestamp(datetime("2022-08-29T07:53:10.939000"));
nebula> INSERT VERTEX school(name, found_time) VALUES "DUT":("DUT", timestamp("1988-03-01T08:00:00"));
```

6. 插入点,名称为`dut`,用`now()`或`timestamp()`函数存储时间。
8. 插入点,名称为`dut`,用`now()`或`timestamp()`函数存储时间。

```ngql
# 用 now() 函数存储时间
Expand Down