question

punam.kumari_185226 avatar image
punam.kumari_185226 asked Erick Ramirez edited

Why does Cassandra always save the timezone as UTC with DateTimeOffset?

We are evaluating Cassandra database and found that it always saves the DateTimeoffset in UTC. We have data in different timezones and we need timezone info. I dont want to save timezone in any other field. Is there any way?

EDIT - Additional information.

Here is snippet of code. Saving it as timestamp. Let me know if you need any other details.

CREATE TABLE IF NOT EXISTS Test (bucket int, datetime timestamp, sensor1 text, sensor2 text, PRIMARY KEY(bucket,timestamp)) WITH CLUSTERING ORDER BY (datetime desc);
Insert into Test (bucket, datetime, sensor1, sensor2) values (1, DateTimeoffset.Parse("23-04-2020 10:45:27 +05:30"), '11', '22')
Select * from Test where bucket = 1 and datetime > sometime;
1 2020-04-23T10:45:27.000Z 11 22
csharp driver
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered punam.kumari_185226 commented

@punam.kumari_185226 Cassandra doesn't store timezone information. The timestamp data type is an integer representation of the date and time which has elapsed since the Unix epoch (January 1, 1970) in milliseconds.

The date/time value passed to DataTimeOffset.Parse() is converted to UTC by the C# driver. When your application retrieves the value of a timestamp column, it needs to display (format) the value in the required locale.

For more information, see CQL Timestamp type. Cheers!

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.