4

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?

Boiethios
  • 38,438
  • 19
  • 134
  • 183
zdd
  • 8,258
  • 8
  • 46
  • 75

3 Answers3

8

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)
Paul
  • 81
  • 1
  • 2
  • I shared the documentation related http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc32300.1570/html/sqlug/BABDBAHF.htm – Doberon Feb 01 '18 at 00:19
3

Try this:

select str_replace( convert( varchar, col1, 111 ), '/', '-') 
from table
Robert
  • 25,425
  • 8
  • 67
  • 81
0

Look the table documentation shared by Doberon, the table have all the formats. I try it and works nice:

SELECT convert(char(10),dateadd(month,-1, convert(date,getdate())),112)  from table;

My query format is yyyymmdd.