We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

CONVERT(varchar(10), GETDATE(), 101)  question

Medium Priority
1,238 Views
Last Modified: 2012-05-06
WHERE     (DateTime >= CONVERT(varchar(10), GETDATE() - 1, 101)) AND  (DateTime < CONVERT(varchar(10), GETDATE(), 101)

DateTime = DBSMALLDATE

This gives me all records of the day before .. now i want all the records of the day before .. but only between a certain time. Notation: 2/7/2009 8:00:00 PM

Thanks in advanced
Comment
Watch Question

Commented:
Something like this perhaps -

You could adapt it to suit your filter requirements..
DECLARE @starttime varchar(12), @endtime varchar(12)
SELECT   @starttime = '08:00:000 PM'
	,@endtime   = '09:00:000 PM'
 
SELECT   COMPARISONFROM = DATEADD(d, 0, datediff(d, 0,getdate() - 1)) + cast(@starttime as datetime)
	,COMPARISONTO   = DATEADD(d, 0, datediff(d, 0,getdate() - 1)) + cast(@endtime as datetime)

Open in new window

Author

Commented:
not something like:

DateTime >= CONVERT(varchar(10), GETDATE() - 1, 101) + ' 9:00:0000 PM'
Commented:
Then you need to cast the entire result into a datetime like -

DateTime >= CONVERT(datetime, CONVERT(varchar(10), GETDATE() - 1, 101) + ' 9:00:000 PM')

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
CONVERT(varchar(10), GETDATE() - 1, 101) + ' 7:00:000 AM')  .. Works

why 2x Convert?
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.