Skip to content

Commit

Permalink
datetime2timestamp-and-timestamp2datetime (#1590)
Browse files Browse the repository at this point in the history
  • Loading branch information
abby-cyber authored Sep 7, 2022
1 parent 6923390 commit 7a25976
Showing 1 changed file with 72 additions and 21 deletions.
93 changes: 72 additions & 21 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 @@ -44,7 +44,46 @@ The properties of `time()` include `hour`, `minute`, and `second`.

The `DATETIME` type is used for values that contain both date and time parts. Nebula Graph retrieves and displays `DATETIME` values in `YYYY-MM-DDThh:mm:ss.msmsmsususus` format. The supported range is `-32768-01-01T00:00:00.000000` to `32767-12-31T23:59:59.999999`.

The properties of `datetime()` include `year`, `month`, `day`, `hour`, `minute`, and `second`.
- The properties of `datetime()` include `year`, `month`, `day`, `hour`, `minute`, and `second`.

- `datetime()` can convert `TIMESTAMP` to `DATETIME`. The value range of `TIMESTAMP` is `0~9223372036`.

- `datetime()` supports an `int` argument. The `int` argument specifies a timestamp.


```ngql
# To get the current date and time.
nebula> RETURN datetime();
+----------------------------+
| datetime() |
+----------------------------+
| 2022-08-29T06:37:08.933000 |
+----------------------------+
# To get the current hour.
nebula> RETURN datetime().hour;
+-----------------+
| datetime().hour |
+-----------------+
| 6 |
+-----------------+
# To get date time from a given timestamp.
nebula> RETURN datetime(timestamp(1625469277));
+---------------------------------+
| datetime(timestamp(1625469277)) |
+---------------------------------+
| 2021-07-05T07:14:37.000000 |
+---------------------------------+
nebula> RETURN datetime(1625469277);
+----------------------------+
| datetime(1625469277) |
+----------------------------+
| 2021-07-05T07:14:37.000000 |
+----------------------------+
```

## TIMESTAMP

The `TIMESTAMP` data type is used for values that contain both date and time parts. It has a range of `1970-01-01T00:00:01` UTC to `2262-04-11T23:47:16` UTC.
Expand All @@ -57,30 +96,42 @@ The `TIMESTAMP` data type is used for values that contain both date and time par

- Supported `TIMESTAMP` inserting methods: timestamp, `timestamp()` function, and `now()` function.

- `timestamp()` function accepts empty parameters to get the timestamp of the current timezone and also accepts a string type parameter.
- `timestamp()` function accepts empty arguments to get the timestamp of the current timezone.

```ngql
# Return the current time.
nebula> RETURN timestamp();
+-------------+
| timestamp() |
+-------------+
| 1625469277 |
+-------------+
nebula> RETURN timestamp("2022-01-05T06:18:43");
+----------------------------------+
| timestamp("2022-01-05T06:18:43") |
+----------------------------------+
| 1641363523 |
+----------------------------------+
```
- `timestamp()` function can convert `DATETIME` to `TIMESTAMP`. The data type of `DATETIME` should be a `string`.

!!! compatibility "Legacy version compatibility"
- The underlying storage data type is **int64**.

In NebulaGraph versions earlier than 3.0.0, the time string passed into the timestamp() function could include milliseconds and microseconds. As of version 3.0.0, the time string passed into the timestamp() function cannot include milliseconds and microseconds.
```ngql
# To get the current timestamp.
nebula> RETURN timestamp();
+-------------+
| timestamp() |
+-------------+
| 1625469277 |
+-------------+
# To get a timestamp from given date and time.
nebula> RETURN timestamp("2022-01-05T06:18:43");
+----------------------------------+
| timestamp("2022-01-05T06:18:43") |
+----------------------------------+
| 1641363523 |
+----------------------------------+
# To get a timestamp using datetime().
nebula> RETURN timestamp(datetime("2022-08-29T07:53:10.939000"));
+---------------------------------------------------+
| timestamp(datetime("2022-08-29T07:53:10.939000")) |
+---------------------------------------------------+
| 1661759590 |
+---------------------------------------------------+
```

!!! note

The date and time format string passed into `timestamp()` cannot include any millisecond and microsecond, but the date and time format string passed into `timestamp(datetime())` can include a millisecond and a microsecond.

- The underlying storage data type is **int64**.

## DURATION

Expand Down

0 comments on commit 7a25976

Please sign in to comment.