
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 with your CQL shell, you'll notice that the dates do not tell you when the rows were created but when the UUIDs in the id column were generated. Since we're using UUIDs that I generated when writing this book, we'll see that the creation 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: