| Author |
Topic |
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2009-01-15 : 13:57:01
|
| How can i use in my select query condition to get just todaye's date records only.where sent_date = Todays_Date()Thank you.. |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-01-15 : 14:08:59
|
| look for getdate() |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-01-15 : 14:12:41
|
| remember to exclude the timestamp while comparing two dates |
 |
|
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2009-01-15 : 14:13:39
|
How can i exclude timestamp() from Getdate()...Thank you for the information.quote: Originally posted by rohitkumar remember to exclude the timestamp while comparing two dates
|
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-01-15 : 14:20:17
|
| [code]where sent_date =DATEADD(DAY, 0, DATEDIFF(DAY, 0, getdate())) [/code] |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-01-15 : 14:23:12
|
| and I would exclude timestamp from sent_date too in a similar way |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-01-15 : 23:18:07
|
| Try this also, select dateadd(d,0,datediff(d,0,current_timestamp)) |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2009-01-16 : 00:01:47
|
| select * from urtable where datediff(d,sent_date,getdate()) = 0Jai Krishna |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 00:06:25
|
quote: Originally posted by sakets_2000
where sent_date =DATEADD(DAY, 0, DATEDIFF(DAY, 0, getdate()))
will work only if you dont have timepart for date values |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 00:09:04
|
quote: Originally posted by Jai Krishna select * from urtable where datediff(d,sent_date,getdate()) = 0Jai Krishna
if you want to use index on datefield useselect * from urtable where sent_date>=dateadd(dd,datediff(dd,0,getdate()),0) and sent_date<dateadd(dd,datediff(dd,0,getdate()),1) |
 |
|
|
thiyagu_rind
Starting Member
46 Posts |
Posted - 2009-01-16 : 00:27:42
|
| Hi, Try the below also,WHERE CONVERT(VARCHAR(10), SENT_DATE,103) = CONVERT(VARCHAR(10), GETDATE(),103)RegardsThiyagarajanwww.sqlhunt.blogspot.com |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-16 : 01:28:32
|
| TRY this select * from URTABLE WHERE LEFT(SENT_DATE,11)= LEFT(GETDATE(),11) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 02:50:54
|
| please dont convert date values to varchar for comparison. use any of the other suggestions given. Try to preserve the datetime datatype. |
 |
|
|
ra.shinde
Posting Yak Master
103 Posts |
Posted - 2009-01-16 : 03:03:15
|
| Converting to varchar in where clause will not change datatype in resultRahul Shinde |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-16 : 03:17:25
|
quote: Originally posted by ra.shinde Converting to varchar in where clause will not change datatype in resultRahul Shinde
that i know its better to preserve the original datatype of field especially when you're using comparison operators like >,<,... |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-16 : 03:51:21
|
| good suggestion visakh,try thiswhere dateadd(d,0,datediff(d,0,sent_Date)) = dateadd(d,0,datediff(d,0,getdate())) |
 |
|
|
thiyagu_rind
Starting Member
46 Posts |
Posted - 2009-01-16 : 04:07:43
|
| hi, I hope it will better to use the code given Jai Krishna. You can try the below method also.Code Snippet:Where datediff(d,0,sent_date) = datediff(d,0,getdate()) RegardsThiyagarajanwww.sqlhunt.blogspot.com |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-01-16 : 06:04:57
|
quote: Originally posted by thiyagu_rind hi, I hope it will better to use the code given Jai Krishna. You can try the below method also.Code Snippet:Where datediff(d,0,sent_date) = datediff(d,0,getdate()) RegardsThiyagarajanwww.sqlhunt.blogspot.com
Thiyagarajan,It works but you need to use index As well. So it is better to go with Visakh's approach. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-01-16 : 07:22:45
|
quote: Originally posted by bklr TRY this select * from URTABLE WHERE LEFT(SENT_DATE,11)= LEFT(GETDATE(),11)
Dont convert date values to VARCHARsYou have been already told thisLearn from the answers posted MadhivananFailing to plan is Planning to fail |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-01-16 : 07:25:16
|
quote: Originally posted by madhivanan
quote: Originally posted by bklr TRY this select * from URTABLE WHERE LEFT(SENT_DATE,11)= LEFT(GETDATE(),11)
Dont convert date values to VARCHARsYou have been already told thisLearn from the answers posted MadhivananFailing to plan is Planning to fail
after that i have given this sol also where dateadd(d,0,datediff(d,0,sent_Date)) = dateadd(d,0,datediff(d,0,getdate())) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-01-16 : 07:36:33
|
quote: Originally posted by bklr
quote: Originally posted by madhivanan
quote: Originally posted by bklr TRY this select * from URTABLE WHERE LEFT(SENT_DATE,11)= LEFT(GETDATE(),11)
Dont convert date values to VARCHARsYou have been already told thisLearn from the answers posted MadhivananFailing to plan is Planning to fail
after that i have given this sol also where dateadd(d,0,datediff(d,0,sent_Date)) = dateadd(d,0,datediff(d,0,getdate()))
See Visakh's second replyThats most likely make use of indexAvoid using functions on columns in the WHERE clauseMadhivananFailing to plan is Planning to fail |
 |
|
|
Next Page
|