ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Server
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Download
ScyllaDB Docs Scylla Rust Driver Data Types Date

Caution

You're viewing documentation for an unstable version of Scylla Rust Driver. Switch to the latest stable version.

Date¶

Depending on feature flags, three different types can be used to interact with date.

Internally date is represented as number of days since -5877641-06-23 i.e. 2^31 days before unix epoch.

CqlDate¶

Without any extra features enabled, only value::CqlDate is available. It’s an u32 wrapper and it matches the internal date representation.

However, for most use cases other types are more practical. See following sections for chrono and time.

use scylla::value::CqlDate;
use futures::TryStreamExt;

// 1970-01-08
let to_insert = CqlDate((1 << 31) + 7);

// Insert date into the table
session
    .query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
    .await?;

// Read raw Date from the table
let mut iter = session.query_iter("SELECT a FROM keyspace.table", &[])
    .await?
    .rows_stream::<(CqlDate,)>()?;
while let Some((date_value,)) = iter.try_next().await? {
    // ...
}

chrono::NaiveDate¶

If full range is not required and chrono-04 feature is enabled, chrono::NaiveDate can be used. chrono::NaiveDate supports dates from -262145-01-01 to 262143-12-31.

use chrono::NaiveDate;
use futures::TryStreamExt;

// 2021-03-24
let to_insert = NaiveDate::from_ymd_opt(2021, 3, 24).unwrap();

// Insert date into the table
session
    .query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
    .await?;

// Read NaiveDate from the table
let mut iter = session.query_iter("SELECT a FROM keyspace.table", &[])
    .await?
    .rows_stream::<(NaiveDate,)>()?;
while let Some((date_value,)) = iter.try_next().await? {
    // ...
}

time::Date¶

Alternatively, the time-03 feature can be used to enable support of time::Date. time::Date’s value range depends on feature flags, see its documentation to get more info.

use futures::TryStreamExt;
use time::{Date, Month};

// 2021-03-24
let to_insert = Date::from_calendar_date(2021, Month::March, 24).unwrap();

// Insert date into the table
session
    .query_unpaged("INSERT INTO keyspace.table (a) VALUES(?)", (to_insert,))
    .await?;

// Read Date from the table
let mut iter = session.query_iter("SELECT a FROM keyspace.table", &[])
    .await?
    .rows_stream::<(Date,)>()?;
while let Some((date_value,)) = iter.try_next().await? {
    // ...
}

Was this page helpful?

PREVIOUS
Timeuuid
NEXT
Time
  • Create an issue
  • Edit this page

On this page

  • Date
    • CqlDate
    • chrono::NaiveDate
    • time::Date
Scylla Rust Driver
  • main
    • main
    • v1.1.0
    • v1.0.0
  • Scylla Rust Driver
  • Quick Start
    • Creating a project
    • Connecting and running a simple query
    • Running Scylla using Docker
  • Connecting to the cluster
    • Compression
    • Authentication
    • TLS
  • Executing CQL statements - best practices
    • Unprepared statement
    • Statement values
    • Query result
    • Prepared statement
    • Batch statement
    • Paged query
    • USE keyspace
    • Schema agreement
    • Lightweight transaction (LWT) statement
    • Request timeouts
    • Timestamp generators
  • Execution profiles
    • Creating a profile and setting it
    • All options supported by a profile
    • Priorities of execution settings
    • Remapping execution profile handles
  • Data Types
    • Bool, Tinyint, Smallint, Int, Bigint, Float, Double
    • Ascii, Text, Varchar
    • Counter
    • Blob
    • Inet
    • Uuid
    • Timeuuid
    • Date
    • Time
    • Timestamp
    • Duration
    • Decimal
    • Varint
    • List, Set, Map
    • Tuple
    • User defined types
    • Vector
  • Load balancing
    • DefaultPolicy
  • Retry policy configuration
    • Fallthrough retry policy
    • Default retry policy
    • Downgrading consistency retry policy
  • Speculative execution
    • Simple speculative execution
    • Percentile speculative execution
  • Driver metrics
  • Migration guides
    • Adjusting code to changes in serialization API introduced in 0.11
    • Adjusting code to changes in deserialization API introduced in 0.15
  • Logging
  • Query tracing
    • Tracing a simple/prepared/batch query
    • Tracing a paged query
    • Tracing Session::prepare
    • Query Execution History
  • Schema
Docs Tutorials University Contact Us About Us
© 2025, ScyllaDB. All rights reserved. | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 08 May 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.6