Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

get todays date and a certain time

0 views
Skip to first unread message

AKors...@gmail.com

unread,
Sep 27, 2006, 2:36:59 PM9/27/06
to
Hi Everyone,

I am trying to write something to give me back all the data for a
sertain time range for today.
So for example: I need to get all records where change_date is <= today
2pm and > today at 8pm.
I know i can get just the date for today by using
CONVERT(CHAR(10),getdate(),102) but can i add a time range to that?

Thanks in advance,
Anna

Razvan Socol

unread,
Sep 28, 2006, 12:43:09 AM9/28/06
to
You can use DATEADD, for example:

SELECT DATEADD(hour,14,CONVERT(CHAR(10),getdate(),102))

Razvan

Hugo Kornelis

unread,
Sep 28, 2006, 7:00:37 PM9/28/06
to

Hi Anna,

Use either

CONVERT(datetime, CONVERT(CHAR(10), getdate(), 126) + 'T14:00:00')

or

DATEADD(day, DATEDIFF(day, 0, getdate()), '14:00:00')

to get current date with a time of 2PM.

--
Hugo Kornelis, SQL Server MVP

0 new messages