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 |
|
majidbhutta
Starting Member
13 Posts |
Posted - 2005-11-30 : 00:47:12
|
| Comparing only Time in Sql?Hi Dears!I have two Different DateTime Values i want to Compare only their times independent of Dates How to do it?letDateTime @dt1='2004-10-30 19:30:00.917'DateTime @dt2='2005-11-29 15:00:00.917'accordint to my requirements@dt1>=@dt2 should be true as 19:30>=15:00because i have to compare only the time not the Date how to achieve this in sql .Function required.Thnx In Advance |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-11-30 : 01:01:39
|
| use convert(char(8), @dt1, 108)-----------------[KH] |
 |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-11-30 : 01:04:36
|
| Declare @dt1 datetimeDeclare @dt2 datetimeSelect @dt1='2004-10-30 19:30:00.917'Select @dt2='2005-11-29 15:00:00.917'Print convert(varchar(26),@dt1,108)Print convert(varchar(26),@dt2,108)If convert(varchar(26),@dt1,108) > convert(varchar(26),@dt2,108) Print 'Yes'else Print 'No'---- OR -------Declare @dt1 varchar(25)Declare @dt2 varchar(25)Select @dt1='2004-10-30 19:30:00.917'Select @dt2='2005-11-29 15:00:00.917'Print substring(@dt1,12,len(@dt1))Print substring(@dt2,12,len(@dt2))If substring(@dt1,11,len(@dt1)) > substring(@dt2,11,len(@dt2)) Print 'Yes'else Print 'No'Surendra |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-30 : 02:49:52
|
| http://vyaskn.tripod.com/searching_date_time_values.htmMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|