question

sharon avatar image
sharon asked

Date/TIME T-SQL

I am trying to schedule SSRS report to run a query where the date and time as below date >= '2010-04-29 04:00:01.000' and date <'2010-04-30 04:00:00.000'

However, I can't schedule it to run automatically as the date and time needs to be specified. Can someone help me in converting the date and time to t-sql script. Thanks for your help!

t-sqlssrsschedule
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sharon avatar image
sharon answered

Got it. Here is the script I will be using

declare @begdate datetime declare @enddate datetime

Set @begdate = dateadd(hh,4,DATEADD(dd, DATEDIFF(dd, 0, GETDATE())-1, 0)) Set @enddate = dateadd(hh,4,DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0))

select * from customer where date >= @begdate and date < @enddate

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

TimothyAWiseman avatar image
TimothyAWiseman answered

I am not sure I am understanding the question. If you want to turn those strings into datetimes for comparisons, just use the cast (ANSI sql) or convert (T-SQL) functions to convert them. In fact, the optimizer will implicitly convert them from that format if you compare them to a datetime value.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sharon avatar image sharon commented ·
Hi there, I am trying to find out how to convert this script using getdate() select * from customer where date >= '2010-04-29 04:00:01.000' and date <'2010-04-30 04:00:00.000' order by date
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.