PLANNED MAINTENANCE

Hello, DataStax Community!

We want to make you aware of a few operational updates which will be carried out on the site. We are working hard to streamline the login process to integrate with other DataStax resources. As such, you will soon be prompted to update your password. Please note that your username will remain the same.

As we work to improve your user experience, please be aware that login to the DataStax Community will be unavailable for a few hours on:

  • Wednesday, July 15 16:00 PDT | 19:00 EDT | 20:00 BRT
  • Thursday, July 16 00:00 BST | 01:00 CEST | 04:30 IST | 07:00 CST | 09:00 AEST

For more info, check out the FAQ page. Thank you for being a valued member of our community.


question

punam.kumari_185226 avatar image
punam.kumari_185226 asked ·

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
cassandradriverc#
10 |1000 characters needed characters left characters exceeded

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 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 characters needed characters left characters exceeded

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