How to convert a string to a date in sybase

纵然是瞬间 提交于 2019-11-27 01:02:24

问题


I need to specify a date value in a sybase where clause. For example:

select * 
from data
where dateVal < [THE DATE]

回答1:


Use the convert function, for example:

select * from data 
where dateVal < convert(datetime, '01/01/2008', 103)

Where the convert style (103) determines the date format to use.




回答2:


Here's a good reference on the different formatting you can use with regard to the date:

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/Convert.htm




回答3:


Several ways to accomplish that but be aware that your DB date_format option & date_order option settings could affect the incoming format:

Select 
   cast('2008-09-16' as date)
   convert(date,'16/09/2008',103)
   date('2008-09-16')
from dummy;



回答4:


102 is the rule of thumb, convert (varchar, creat_tms, 102) > '2011'



来源:https://stackoverflow.com/questions/56303/how-to-convert-a-string-to-a-date-in-sybase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!