17

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

select * 
from data
where dateVal < [THE DATE]
mtk
  • 13,221
  • 16
  • 72
  • 112
cmsherratt
  • 2,129
  • 3
  • 15
  • 13

4 Answers4

25

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.

cmsherratt
  • 2,129
  • 3
  • 15
  • 13
8

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

abcalphabet
  • 1,158
  • 3
  • 16
  • 31
Edwin
  • 93
  • 1
  • 3
4

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;
Sully
  • 14,672
  • 5
  • 54
  • 79
Jose B.
  • 897
  • 1
  • 10
  • 13
-1

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

Jackie
  • 25,199
  • 6
  • 33
  • 24