Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


event is occurring between today at 1:00am and tomorrow at 12:59am


event is occurring between today at 1:00am and tomorrow at 12:59am

Author
Message
dallas13
dallas13
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1193 Visits: 1133
Hello,

I need a query that finds event is occurring between today at 1:00 am and tomorrow at 12:59 am. I have 2 columns.event_date datatype =date and event_time datatype= time
This query gives me,
SELECT CONVERT(datetime, CONVERT(varchar, DATEADD(day, 0, GETDATE()), 102))
--2013-03-19 00:00:00.000 but instead of 0.00 I need my time whihc is 1:00 AM and 12:59 AM of next day.
Lynn Pettis
Lynn Pettis
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24278 Visits: 37987
Something like this, just off the top of my head:



declare @StartDate datetime,
@EndDate datetime;
select
@StartDate = dateadd(hh, 1,dateadd(dd, datediff(dd, 0, getdate()), 0)),
@EndDate = dateadd(dd, 1, @StartDate);

select ...
from mytable mt
where mt.someeventdatetime >= @StartDate and mt.someeventdatetime < @EndDate;




Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Sergiy
Sergiy
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5852 Visits: 11412
Just to annoy you Lynn :-D


select ...
from mytable mt
inner join (
select dateadd(hh, 1, dateadd(dd, datediff(dd, 0, getdate()), 0)) StartDate
) DT ON mt.someeventdatetime >= DT.StartDate and mt.someeventdatetime < dateadd(dd, 1, DT.StartDate);




I guess it's your turn now.Hehe

On a serious note, it could be useful to add a computed column to the table:

DATEADD(dd, DATEDIFF(dd, 0, DATEADD(hh, -1, someeventdatetime )), 0) RegistryDate



or, if it's not an option, create a view like this:

select DATEADD(dd, DATEDIFF(dd, 0, DATEADD(hh, -1, someeventdatetime )), 0) RegistryDate
, *
from mytable mt



It will indicate which day any registered event belongs to.
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