Database Reference
In-Depth Information
Extracting timestamps
As we previously mentioned, Cassandra has special capabilities for the
timeuuid
type,
which includes extracting the timestamp that's encoded in these UUIDs. We can see this in
action using the
DATEOF
function:
SELECT "username", "id", "body", DATEOF("id")
FROM "user_status_updates";
The
DATEOF
function instructs Cassandra to return a result column containing the
timestamp at which the given column's UUID value was created. We now have access to
information encoded in the
id
column that was previously obscure:
If you're following along in your CQL shell, you'll notice that the dates do not tell you
when the rows were created, but rather when the UUIDs in the
id
column were generated.
Since we're using UUIDs that I generated when writing this topic, we'll see that the cre-
ation timestamp shows an older time.
While the
DATEOF
output is very readable, the timestamps only offer precision at the
second level. For a more precise representation of the timestamp at which the UUIDs were
generated, use the
UNIXTIMESTAMPOF
function instead:
SELECT "username", "id", "body", UNIXTIMESTAMPOF("id")
FROM "user_status_updates";
The
UNIXTIMESTAMPOF
function returns the timestamp represented as the number of
milliseconds since January 1, 1970 at midnight UTC: