【问题标题】:How to convert a string to a date in sybase如何在sybase中将字符串转换为日期
【发布时间】:2010-09-08 13:12:33
【问题描述】:

我需要在 sybase where 子句中指定一个日期值。例如:

select * 
from data
where dateVal < [THE DATE]

【问题讨论】:

    标签: sybase type-conversion


    【解决方案1】:

    使用转换函数,例如:

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

    转换样式 (103) 确定要使用的日期格式。

    【讨论】:

      【解决方案2】:

      这里有一个很好的参考,您可以在日期方面使用不同的格式:

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

      【讨论】:

      • 提供的链接已失效。
      【解决方案3】:

      有几种方法可以实现,但请注意您的数据库 date_format optiondate_order option 设置可能会影响传入格式:

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

      【讨论】:

        【解决方案4】:

        102 是经验法则, 转换(varchar,creat_tms,102)>'2011'

        【讨论】:

          猜你喜欢
          • 2010-12-24
          • 2010-12-25
          • 2020-04-06
          • 1970-01-01
          • 1970-01-01
          • 2020-05-24
          • 1970-01-01
          • 2017-06-16
          • 1970-01-01
          相关资源
          最近更新 更多