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.
| 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 reardsCheersRam |
|
|
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 thisMalathi Rao |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-07-16 : 07:04:59
|
| www.sql-server-performance.com/fk_datetime.aspMadhivananFailing to plan is Planning to fail |
 |
|
|
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))) |
 |
|
|
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 postedMadhivananFailing to plan is Planning to fail |
 |
|
|
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 reardsCheersRam
You're making it too complicated. This should do what you want.Select convert(varchar(10),[date],103)from tbl_eventwhere [date] >= dateadd(dd,datediff(dd,0,getdate()),0) CODO ERGO SUM |
 |
|
|
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 alotCheersRam |
 |
|
|
|
|
|
|
|