Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sybase How to get dash separated date yyyy-mm-dd?

I want to get date in such format yyyy-mm-dd, for example 2014-04-11. But it seems there is no way to do this in Sybase (ASE 12.5) with the convert function.

Currently, I get the date by 112 and add the - between digits. Any good way?

like image 652
zdd Avatar asked Dec 19 '22 16:12

zdd


2 Answers

Take advantage of format 140: yyyy-mm-dd hh:mm:ss.ssssss

Use char(10) to make Sybase truncate the string to just the first 10 characters, i.e.

convert(char(10), col1, 140)
like image 180
Paul Avatar answered Jan 14 '23 06:01

Paul


Try this:

select str_replace( convert( varchar, col1, 111 ), '/', '-') 
from table
like image 38
Robert Avatar answered Jan 14 '23 06:01

Robert