Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Date Comarision problem please help

Author  Topic 

BuddyRam
Starting Member

17 Posts

Posted - 2007-07-16 : 06:23:27
Hello,
I have to compare the two date time fields but I have to check the date part only.
I am using folloowing query:
Select convert(varchar(10),[date],103) from tbl_event where convert(varchar(10),[date],103)>= Convert(varchar(10),getdate(), 103);

but its not comaring correctly whem I am saying >= then it is giving all values from that table except matching date record.

some one can help in this reards

Cheers
Ram

jogin malathi
Posting Yak Master

117 Posts

Posted - 2007-07-16 : 06:41:46
Select convert(datetime,date],103) from tbl_event where convert(datetime,date],103)>= Convert(datetime,getdate(), 103);

try with this

Malathi Rao
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-16 : 07:04:59
www.sql-server-performance.com/fk_datetime.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Jim77
Constraint Violating Yak Guru

440 Posts

Posted - 2007-07-16 : 10:01:02
I use this technique to make all date time columns have a 00:00:00 time and then they will compare like for like if the dates are the same:

Select convert(datetime,[date],103) from tbl_event
where convert(datetime,(convert(varchar,[date],103))) >=
convert(datetime,(convert(varchar,getdate(),103)))


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-16 : 10:18:38
quote:
Originally posted by Jim77

I use this technique to make all date time columns have a 00:00:00 time and then they will compare like for like if the dates are the same:

Select convert(datetime,[date],103) from tbl_event
where convert(datetime,(convert(varchar,[date],103))) >=
convert(datetime,(convert(varchar,getdate(),103)))





You dont need double convertions. Read the artilce I posted

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-07-16 : 10:47:38
quote:
Originally posted by BuddyRam

Hello,
I have to compare the two date time fields but I have to check the date part only.
I am using folloowing query:
Select convert(varchar(10),[date],103) from tbl_event where convert(varchar(10),[date],103)>= Convert(varchar(10),getdate(), 103);

but its not comaring correctly whem I am saying >= then it is giving all values from that table except matching date record.

some one can help in this reards

Cheers
Ram


You're making it too complicated. This should do what you want.

Select
convert(varchar(10),[date],103)
from
tbl_event
where
[date] >= dateadd(dd,datediff(dd,0,getdate()),0)



CODO ERGO SUM
Go to Top of Page

BuddyRam
Starting Member

17 Posts

Posted - 2007-07-19 : 02:38:52
Thanks for all your work I make it work now throug your suggestions..thanks alot

Cheers
Ram
Go to Top of Page
   

- Advertisement -