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
) forfirst_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
) forbirthday
.
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
WARNING: cqlsh was built against 5.0-beta1, but this server is 5.0. All features may not work!
first_race | last_race | birthday
------------+------------+------------
2006-03-15 | 2024-06-21 | 1989-07-05
(1 rows)