all groups > sql server (alternate) > september 2006 >
You're in the

sql server (alternate)

group:

get todays date and a certain time


get todays date and a certain time AKorsakova NO[at]SPAM gmail.com
9/27/2006 11:36:59 AM
sql server (alternate):
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
Re: get todays date and a certain time Razvan Socol
9/27/2006 9:43:09 PM
You can use DATEADD, for example:

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

Razvan

[quoted text, click to view]
Re: get todays date and a certain time Hugo Kornelis
9/29/2006 1:00:37 AM
[quoted text, click to view]

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.

--
AddThis Social Bookmark Button