Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cockroachdb format datetime in select query

I'm trying to format a timestamp value to yyyymmdd in cockroach DB select query.

In MySQL, we can format a date using DATE_FORMAT()

E.g. SELECT DATE_FORMAT(created_at, "%Y-%m-%d") FROM users to fetch result into a desired format.

What would be an alternative of DATE_FORMAT() we can use in cockroach DB?

like image 318
Hashmat Avatar asked Mar 20 '26 00:03

Hashmat


1 Answers

You can use the experimental builtin experimental_strftime which uses the strftime syntax.

SELECT experimental_strftime(created_at, '%Y-%m-%d') FROM users

Alternatively, you can use experimental_strptime which uses the strptime syntax.

Please take the time to read the important notes about experimental features. The time formatting builtins are experimental because they behave differently on different platforms.

like image 169
Marc Avatar answered Mar 22 '26 10:03

Marc