DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


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.