如何在Sybase中获取以破折号分隔的日期格式yyyy-mm-dd?

4
我希望以这种格式yyyy-mm-dd获取日期,例如2014-04-11。但是在Sybase(ASE 12.5)中使用convert函数似乎无法实现。
目前,我通过112获取日期并在数字之间添加-。有更好的方法吗?

1
你的Sybase数据库是哪种类型?IQ,ASE,ASA? - Robert
3个回答

8

利用格式140:年-月-日 时:分:秒.毫秒

使用char(10)使Sybase将字符串截断为前10个字符,即:

convert(char(10), col1, 140)

我分享了与http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc32300.1570/html/sqlug/BABDBAHF.htm相关的文档。 - Doberon

3

试试这个:

select str_replace( convert( varchar, col1, 111 ), '/', '-') 
from table

0

看看Doberon分享的表格文档,表格中包含所有格式。我尝试了一下,效果很好:

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

我的查询格式是yyyymmdd。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接