greater or equal in sql

# Thread: greater or equal in sql

1. Senior Member
Join Date
Dec 1969
Posts
380

## greater or equal in sql

hello,<BR><BR>ain&#039;t it possible to do a greator or equal in sql statments?<BR><BR>i use this and just saw that it&#039;s not 100% working<BR><BR>MySQL="Select * from tradeshow where (startdate &#062;= getdate() or enddate &#062;= getdate() ) order by startdate"<BR><BR>when startdate or enddate is the same as today it not selected<BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: greater or equal in sql

Are you sure you want<BR><BR>StartDate greater than, or equal to today&#039;s date<BR><BR>AND<BR><BR>EndDate greater than, or equal to today&#039;s date<BR><BR><BR>but to your problem:<BR><BR>Problem with GetDate is, it also returns the Time, so you&#039;d need to match the time as well. A workaround is:<BR><BR>SELECT [...]<BR>FROM tradeshow WHERE DateDiff(d,startDate,GetDate()) &#062; 0<BR><BR>or <BR><BR>CONVERT(CHAR(10,startdate,105) = convert(CHAR(10), GetDate())<BR><BR>check BOL for more info on CONVERT

3. Senior Member
Join Date
Dec 1969
Posts
380

## RE: greater or equal in sql

well, the startdate & enddate field only contain the date so that shouldn&#039;t be the problem or does it see those as 0:00 then?<BR><BR>will try it out with the datediff maybe that solves my problem

4. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: greater or equal in sql

&#062;&#062;&#062;&#062; well, the startdate & enddate field only contain the date so that shouldn&#039;t be the problem <BR><BR>Just that *is* the problem!<BR><BR>e.g. startdate contains &#039;01/01/2003 00:00.000&#039; getdate returns &#039;01/01/2003 12:23.005&#039;<BR><BR>those two don&#039;t match.<BR><BR>&#062;&#062; or does it see those as 0:00 then?<BR><BR>Yes, a DateTime field includes *always* the time, if you omit the time with an insert, it&#039;s default filled with 00:00.000. <BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
380

## RE: greater or equal in sql

didn&#039;t know that...<BR><BR>solved it with this thanks to you<BR><BR>MySQL="Select * from tradeshow where (DateDiff(d,getdate(),startDate) &#062; -1 or DateDiff(d,getdate(),enddate) &#062; -1 ) order by startdate"

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•