Date column

Write values using the current day/time or a string format into a date column.

String format

date

date string format:

<yyyy>-<mm>-<dd>

Where the elements of a date are separated with a hyphen:

  • yyyy: four-digit year

  • mm: two-digit month

  • dd: two-digit day

For example, May 5, 2017:

2017-05-05

Getting the current day

Use toDate(now()) to insert the current day into a date field.

  • To INSERT dates:

    • Current date (today) for last_race values.

INSERT INTO cycling.cyclist_alt_stats (id,last_race) 
  VALUES (ed584e99-80f7-4b13-9a90-9dc5571e6821,todate(now()));
INSERT INTO cycling.cyclist_alt_stats (id,last_race) 
  VALUES (ed584e99-80f7-4b13-9a90-9dc5571e6821,todate(now()));
  • String format (yyyy-mm-dd) for first_race value.

INSERT INTO cycling.cyclist_alt_stats (id,first_race) 
  VALUES (ed584e99-80f7-4b13-9a90-9dc5571e6821,'2006-03-15');
INSERT INTO cycling.cyclist_alt_stats (id,first_race) 
  VALUES (ed584e99-80f7-4b13-9a90-9dc5571e6821,'2006-03-15');
  • To UPDATE a date field:

    • Current date (today) for last_race.

UPDATE cycling.cyclist_alt_stats SET last_race = toDate(now())
  WHERE id = ed584e99-80f7-4b13-9a90-9dc5571e6821;
  • Use formatted string (yyyy-mm-dd) for birthday.

UPDATE cycling.cyclist_alt_stats SET birthday = '1987-03-07'
  WHERE id = ed584e99-80f7-4b13-9a90-9dc5571e6821;

Select the date columns from the table.

SELECT first_race, last_race, birthday FROM cycling.cyclist_alt_stats
  WHERE id = ed584e99-80f7-4b13-9a90-9dc5571e6821;
Results
 first_race | last_race  | birthday
------------+------------+------------
 2006-03-15 | 2024-07-01 | 1989-07-05

(1 rows)

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com