SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help with datetime column


Help with datetime column

Author
Message
ishaan99
ishaan99
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2984 Visits: 295
I need to extract data from a table where created data >=yday data <=2 in the morning. This is what i have. Cutently it takes data only till 12 am for today how do i change it to accept tilll today 2 in the morning. any help will be greatly appreciated. Since it a dattime time i am nota bel to append it with '02:00:00' also. TIA

SELECT DISTINCT * friom tableA
where (cast(h.created as datetime)>= convert(datetime, floor(convert(float, getdate()-1)))
and cast(h.created as datetime) < convert(datetime, floor(convert(float, getdate()))))



andy.gear
andy.gear
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 133
Does this give you what you want?
select cast(convert(varchar(10),getdate(),101)+' 02:00AM' as DateTime)
GSquared
GSquared
SSC Guru
SSC Guru (140K reputation)SSC Guru (140K reputation)SSC Guru (140K reputation)SSC Guru (140K reputation)SSC Guru (140K reputation)SSC Guru (140K reputation)SSC Guru (140K reputation)SSC Guru (140K reputation)

Group: General Forum Members
Points: 140359 Visits: 9731
Change:


and cast(h.created as datetime) < convert(datetime, floor(convert(float, getdate()))))



to:


and cast(h.created as datetime) < dateadd(hour, 2, convert(datetime, floor(convert(float, getdate())))))



- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Michael Valentine Jones
Michael Valentine Jones
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36248 Visits: 11933
select  distinct *
from
tableA
where
-- Greater than or equal to yesterday at 00:00:00.000 (midnight)
h.created >= dateadd(dd,datediff(dd,0,getdate())-1,0)
-- Less than today at 02:00:00.000 (2am)
h.created < dateadd(dd,datediff(dd,0,getdate()),'02:00')


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search