|
9 | 9 |
|
10 | 10 | --- |
11 | 11 |
|
| 12 | +import { Badge } from "~/components" |
| 13 | + |
| 14 | +## formatDateTime |
| 15 | + |
| 16 | +Usage: |
| 17 | + |
| 18 | +```sql |
| 19 | +formatDateTime(<datetime expression>, <format string>[, <timezone string>]) |
| 20 | +``` |
| 21 | + |
| 22 | +`formatDateTime` prints a datetime as a string according to a provided format string. Refer to |
| 23 | +[ClickHouse's documentation](https://clickhouse.com/docs/en/sql-reference/functions/date-time-functions/#formatdatetime) |
| 24 | +for a list of supported formatting options. |
| 25 | + |
| 26 | +Examples: |
| 27 | + |
| 28 | +```sql |
| 29 | +-- prints the current YYYY-MM-DD in UTC |
| 30 | +formatDateTime(now(), '%Y-%m-%d') |
| 31 | + |
| 32 | +-- prints YYYY-MM-DD in the datetime's timezone |
| 33 | +formatDateTime(<a datetime with a timezone>, '%Y-%m-%d') |
| 34 | +formatDateTime(toDateTime('2022-12-01 16:17:00', 'America/New_York'), '%Y-%m-%d') |
| 35 | + |
| 36 | +-- prints YYYY-MM-DD in UTC |
| 37 | +formatDateTime(<a datetime with a timezone>, '%Y-%m-%d', 'Etc/UTC') |
| 38 | +formatDateTime(toDateTime('2022-12-01 16:17:00', 'America/New_York'), '%Y-%m-%d', 'Etc/UTC') |
| 39 | +``` |
| 40 | + |
| 41 | +## now |
| 42 | + |
| 43 | +Usage: |
| 44 | + |
| 45 | +```sql |
| 46 | +now() |
| 47 | +``` |
| 48 | + |
| 49 | +Returns the current time as a DateTime. |
| 50 | + |
| 51 | +## today <Badge text="New" variant="tip" size="small" /> |
| 52 | + |
| 53 | +Usage: |
| 54 | + |
| 55 | +```sql |
| 56 | +now() |
| 57 | +``` |
| 58 | + |
| 59 | +Returns the current date as a `Date`. |
| 60 | + |
12 | 61 | ## toDateTime |
13 | 62 |
|
14 | 63 | Usage: |
@@ -37,58 +86,123 @@ toDateTime('1981-04-12 12:00:04') -- string with datetime in 'YYYY-MM-DD hh:mm:s |
37 | 86 | toDateTime('2022-12-01 16:17:00', 'America/New_York') |
38 | 87 | ``` |
39 | 88 |
|
40 | | -## now |
| 89 | +## toYear <Badge text="New" variant="tip" size="small" /> |
41 | 90 |
|
42 | 91 | Usage: |
43 | 92 |
|
44 | 93 | ```sql |
45 | | -now() |
| 94 | +toYear(<datetime>) |
46 | 95 | ``` |
47 | 96 |
|
48 | | -Returns the current time as a DateTime. |
| 97 | +`toYear` returns the year of a datetime. |
49 | 98 |
|
50 | | -## toUnixTimestamp |
| 99 | +Examples: |
| 100 | + |
| 101 | +```sql |
| 102 | +-- returns the number 2025 |
| 103 | +toYear(toDateTime('2025-10-27 00:00:00')) |
| 104 | +``` |
| 105 | + |
| 106 | +## toMonth <Badge text="New" variant="tip" size="small" /> |
51 | 107 |
|
52 | 108 | Usage: |
53 | 109 |
|
54 | 110 | ```sql |
55 | | -toUnixTimestamp(<datetime>) |
| 111 | +toMonth(<datetime>) |
56 | 112 | ``` |
57 | 113 |
|
58 | | -`toUnixTimestamp` converts a datetime into an integer unix timestamp. |
| 114 | +`toMonth` returns the year of a datetime. |
59 | 115 |
|
60 | 116 | Examples: |
61 | 117 |
|
62 | 118 | ```sql |
63 | | --- get the current unix timestamp |
64 | | -toUnixTimestamp(now()) |
| 119 | +-- returns the number 10 |
| 120 | +toMonth(toDateTime('2025-10-27 00:00:00')) |
65 | 121 | ``` |
66 | 122 |
|
67 | | -## formatDateTime |
| 123 | +## toDayOfMonth <Badge text="New" variant="tip" size="small" /> |
68 | 124 |
|
69 | 125 | Usage: |
70 | 126 |
|
71 | 127 | ```sql |
72 | | -formatDateTime(<datetime expression>, <format string>[, <timezone string>]) |
| 128 | +toDayOfMonth(<datetime>) |
73 | 129 | ``` |
74 | 130 |
|
75 | | -`formatDateTime` prints a datetime as a string according to a provided format string. Refer to |
76 | | -[ClickHouse's documentation](https://clickhouse.com/docs/en/sql-reference/functions/date-time-functions/#formatdatetime) |
77 | | -for a list of supported formatting options. |
| 131 | +`toDayOfMonth` returns the day of the month from a datetime. |
78 | 132 |
|
79 | 133 | Examples: |
80 | 134 |
|
81 | 135 | ```sql |
82 | | --- prints the current YYYY-MM-DD in UTC |
83 | | -formatDateTime(now(), '%Y-%m-%d') |
| 136 | +-- returns the number 27 |
| 137 | +toDayOfMonth(toDateTime('2025-10-27 00:00:00')) |
| 138 | +``` |
84 | 139 |
|
85 | | --- prints YYYY-MM-DD in the datetime's timezone |
86 | | -formatDateTime(<a datetime with a timezone>, '%Y-%m-%d') |
87 | | -formatDateTime(toDateTime('2022-12-01 16:17:00', 'America/New_York'), '%Y-%m-%d') |
| 140 | +## toHour <Badge text="New" variant="tip" size="small" /> |
88 | 141 |
|
89 | | --- prints YYYY-MM-DD in UTC |
90 | | -formatDateTime(<a datetime with a timezone>, '%Y-%m-%d', 'Etc/UTC') |
91 | | -formatDateTime(toDateTime('2022-12-01 16:17:00', 'America/New_York'), '%Y-%m-%d', 'Etc/UTC') |
| 142 | +Usage: |
| 143 | + |
| 144 | +```sql |
| 145 | +toHour(<datetime>) |
| 146 | +``` |
| 147 | + |
| 148 | +`toHour` returns the hour of the day from a datetime. |
| 149 | + |
| 150 | +Examples: |
| 151 | + |
| 152 | +```sql |
| 153 | +-- returns the number 9 |
| 154 | +toHour(toDateTime('2025-10-27 09:11:13')) |
| 155 | +``` |
| 156 | + |
| 157 | +## toMinute <Badge text="New" variant="tip" size="small" /> |
| 158 | + |
| 159 | +Usage: |
| 160 | + |
| 161 | +```sql |
| 162 | +toMinute(<datetime>) |
| 163 | +``` |
| 164 | + |
| 165 | +`toMinute` returns the minute of the hour from a datetime. |
| 166 | + |
| 167 | +Examples: |
| 168 | + |
| 169 | +```sql |
| 170 | +-- returns the number 11 |
| 171 | +toMinute(toDateTime('2025-10-27 09:11:13')) |
| 172 | +``` |
| 173 | + |
| 174 | +## toSecond <Badge text="New" variant="tip" size="small" /> |
| 175 | + |
| 176 | +Usage: |
| 177 | + |
| 178 | +```sql |
| 179 | +toSecond(<datetime>) |
| 180 | +``` |
| 181 | + |
| 182 | +`toSecond` returns the second of the minute from a datetime. |
| 183 | + |
| 184 | +Examples: |
| 185 | + |
| 186 | +```sql |
| 187 | +-- returns the number 13 |
| 188 | +toSecond(toDateTime('2025-10-27 09:11:13')) |
| 189 | +``` |
| 190 | + |
| 191 | +## toUnixTimestamp |
| 192 | + |
| 193 | +Usage: |
| 194 | + |
| 195 | +```sql |
| 196 | +toUnixTimestamp(<datetime>) |
| 197 | +``` |
| 198 | + |
| 199 | +`toUnixTimestamp` converts a datetime into an integer unix timestamp. |
| 200 | + |
| 201 | +Examples: |
| 202 | + |
| 203 | +```sql |
| 204 | +-- get the current unix timestamp |
| 205 | +toUnixTimestamp(now()) |
92 | 206 | ``` |
93 | 207 |
|
94 | 208 | ## toStartOfInterval |
@@ -119,3 +233,111 @@ FROM your_dataset |
119 | 233 | GROUP BY hour |
120 | 234 | ORDER BY hour ASC |
121 | 235 | ``` |
| 236 | + |
| 237 | +## toStartOfYear <Badge text="New" variant="tip" size="small" /> |
| 238 | + |
| 239 | +Usage: |
| 240 | + |
| 241 | +```sql |
| 242 | +toStartOfYear(<datetime>) |
| 243 | +``` |
| 244 | + |
| 245 | +`toStartOfYear` rounds down a datetime to the nearest start of year. This can be useful |
| 246 | +for grouping data into equal-sized time ranges. |
| 247 | + |
| 248 | +Examples: |
| 249 | + |
| 250 | +```sql |
| 251 | +-- round a timestamp down to 2025-01-01 00:00:00 |
| 252 | +toStartOfYear(toDateTime('2025-10-27 00:00:00')) |
| 253 | +``` |
| 254 | + |
| 255 | +## toStartOfMonth <Badge text="New" variant="tip" size="small" /> |
| 256 | + |
| 257 | +Usage: |
| 258 | + |
| 259 | +```sql |
| 260 | +toStartOfMonth(<datetime>) |
| 261 | +``` |
| 262 | + |
| 263 | +`toStartOfMonth` rounds down a datetime to the nearest start of month. This can be useful |
| 264 | +for grouping data into equal-sized time ranges. |
| 265 | + |
| 266 | +Examples: |
| 267 | + |
| 268 | +```sql |
| 269 | +-- round a timestamp down to 2025-10-01 00:00:00 |
| 270 | +toStartOfMonth(toDateTime('2025-10-27 00:00:00')) |
| 271 | +``` |
| 272 | + |
| 273 | +## toStartOfDay <Badge text="New" variant="tip" size="small" /> |
| 274 | + |
| 275 | +Usage: |
| 276 | + |
| 277 | +```sql |
| 278 | +toStartOfDay(<datetime>) |
| 279 | +``` |
| 280 | + |
| 281 | +`toStartOfDay` rounds down a datetime to the nearest start of day. This can be useful |
| 282 | +for grouping data into equal-sized time ranges. |
| 283 | + |
| 284 | +Examples: |
| 285 | + |
| 286 | +```sql |
| 287 | +-- round a timestamp down to 2025-10-27 00:00:00 |
| 288 | +toStartOfDay(toDateTime('2025-10-27 00:00:00')) |
| 289 | +``` |
| 290 | + |
| 291 | +## toStartOfHour <Badge text="New" variant="tip" size="small" /> |
| 292 | + |
| 293 | +Usage: |
| 294 | + |
| 295 | +```sql |
| 296 | +toStartOfHour(<datetime>) |
| 297 | +``` |
| 298 | + |
| 299 | +`toStartOfHour` rounds down a datetime to the nearest start of hour. This can be useful |
| 300 | +for grouping data into equal-sized time ranges. |
| 301 | + |
| 302 | +Examples: |
| 303 | + |
| 304 | +```sql |
| 305 | +-- round a timestamp down to 2025-10-27 16:00:00 |
| 306 | +toStartOfHour(toDateTime('2025-10-27 16:55:25')) |
| 307 | +``` |
| 308 | + |
| 309 | +## toStartOfFifteenMinutes <Badge text="New" variant="tip" size="small" /> |
| 310 | + |
| 311 | +Usage: |
| 312 | + |
| 313 | +```sql |
| 314 | +toStartOfFifteenMinutes(<datetime>) |
| 315 | +``` |
| 316 | + |
| 317 | +`toStartOfFifteenMinutes` rounds down a datetime to the nearest fifteen minutes. This can be useful |
| 318 | +for grouping data into equal-sized time ranges. |
| 319 | + |
| 320 | +Examples: |
| 321 | + |
| 322 | +```sql |
| 323 | +-- round a timestamp down to 2025-10-27 16:45:00 |
| 324 | +toStartOfFifteenMinutes(toDateTime('2025-10-27 16:55:25')) |
| 325 | +``` |
| 326 | + |
| 327 | +## toStartOfMinute <Badge text="New" variant="tip" size="small" /> |
| 328 | + |
| 329 | +Usage: |
| 330 | + |
| 331 | +```sql |
| 332 | +toStartOfMinute(<datetime>) |
| 333 | +``` |
| 334 | + |
| 335 | +`toStartOfMinute` rounds down a datetime to the nearest minute. This can be useful |
| 336 | +for grouping data into equal-sized time ranges. |
| 337 | + |
| 338 | +Examples: |
| 339 | + |
| 340 | +```sql |
| 341 | +-- round a timestamp down to 2025-10-27 16:55:00 |
| 342 | +toStartOfMinute(toDateTime('2025-10-27 16:55:25')) |
| 343 | +``` |
0 commit comments