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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With