ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Deployments
    • Cloud
    • Server
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Install
Ask AI
ScyllaDB Docs ScyllaDB CPP-Rust Driver Using the Driver Data Types The date and time Types

The date and time Types¶

The driver currently uses raw types to handle date and time because date and time handling is often very application specific in C/C++. It currently provides methods to handle converting Epoch (January 1, 1970) time in seconds to and from date/time.

The date type uses an unsigned 32-bit integer (cass_uint32_t) to represent the number of days with Epoch centered at 2^31. Because it’s centered at Epoch it can be used to represent days before Epoch. The time type uses a signed 64-bit integer (cass_int64_t) to represent the number of nanoseconds since midnight and valid values are in the range 0 to 86399999999999.

The following examples both use this schema:

CREATE TABLE date_time (key text PRIMARY KEY,
                        year_month_day date,
                        time_of_day time);

INSERTing the date and time Types¶

#include <time.h>

void insert_date_time(CassSession* session) {

  CassStatement* statement = cass_statement_new("INSERT INTO date_time (key, year_month_day, time_of_day) "
                                                "VALUES (?, ?, ?)", 3);

  time_t now = time(NULL); /* Time in seconds from Epoch */

  /* Converts the time since the Epoch in seconds to the 'date' type */
  cass_uint32_t year_month_day = cass_date_from_epoch(now);

  /* Converts the time since the Epoch in seconds to the 'time' type */
  cass_int64_t time_of_day = cass_time_from_epoch(now);

  cass_statement_bind_string(statement, 0, "xyz");

  /* 'date' uses an unsigned 32-bit integer */
  cass_statement_bind_uint32(statement, 1, year_month_day);

  /* 'time' uses a signed 64-bit integer */
  cass_statement_bind_int64(statement, 2, time_of_day);

  CassFuture* future = cass_session_execute(session, statement);

  /* Handle future result */

  /* CassStatement and CassFuture both need to be freed */
  cass_statement_free(statement);
  cass_future_free(future);
}

SELECTing the date and time Types¶

#include <time.h>

void select_date_time(CassSession* session) {
  CassStatement* statement = cass_statement_new("SELECT * FROM date_time WHERE key = ?", 1);

  CassFuture* future = cass_session_execute(session, statement);

  const CassResult* result = cass_future_get_result(future);
  /* Make sure there's a valid result */
  if (result != NULL && cass_result_row_count(result) > 0) {
    const CassRow* row = cass_result_first_row(result);

    /* Get the value of the "year_month_day" column */
    cass_uint32_t year_month_day;
    cass_value_get_uint32(cass_row_get_column(row, 1), &year_month_day);

    /* Get the value of the "time_of_day" column */
    cass_int64_t time_of_day;
    cass_value_get_int64(cass_row_get_column(row, 2), &time_of_day);

    /* Convert 'date' and 'time' to Epoch time */
    time_t time = (time_t)cass_date_time_to_epoch(year_month_day, time_of_day);
    printf("Date and time: %s", asctime(localtime(&time)));
  } else {
    /* Handle error */
  }

  /* CassStatement and CassFuture both need to be freed */
  cass_statement_free(statement);
  cass_future_free(future);
}

Was this page helpful?

PREVIOUS
Data Types
NEXT
Tuples
  • Create an issue
  • Edit this page

On this page

  • The date and time Types
    • INSERTing the date and time Types
    • SELECTing the date and time Types
ScyllaDB CPP-Rust Driver
  • master
    • master
  • CPP-over-Rust Driver
  • API Documentation
    • CassAggregateMeta
    • CassAuthenticator
    • CassAuthenticatorCallbacks
    • CassBatch
    • CassCluster
    • CassCollection
    • CassColumnMeta
    • CassCustomPayload
    • CassDataType
    • CassErrorResult
    • CassExecProfile
    • CassFunctionMeta
    • CassFuture
    • CassIndexMeta
    • CassInet
    • CassIterator
    • CassKeyspaceMeta
    • CassLogMessage
    • CassMaterializedViewMeta
    • CassMetrics
    • CassNode
    • CassPrepared
    • CassResult
    • CassRetryPolicy
    • CassRow
    • CassSchemaMeta
    • CassSession
    • CassSpeculativeExecutionMetrics
    • CassSsl
    • CassStatement
    • CassTableMeta
    • CassTimestampGen
    • CassTuple
    • CassUserType
    • CassUuid
    • CassUuidGen
    • CassValue
    • CassVersion
  • Getting Started
  • Architecture Overview
  • Installation
  • Building
  • Testing
  • Using the Driver
    • Batches
    • Binding Parameters
    • Client-side timestamps
    • Consistency
    • Data Types
      • The date and time Types
      • Tuples
      • User-Defined Types (UDTs)
      • UUIDs
    • Futures
    • Handling Results
    • Keyspaces
    • Prepared Statements
    • Schema Metadata
  • Configuration
    • Load balancing
    • Retry policies
    • Speculative Execution
    • Connection
    • Execution Profiles
    • Performance Tips
    • Client Configuration
  • Security
    • Authentication
    • TLS
  • Observability
    • Logging
    • Tracing
    • Metrics
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 16 Sep 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.8
Ask AI