Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Parameter Question

Author  Topic 

stharish
Starting Member

43 Posts

Posted - 2012-01-07 : 22:10:24
Microsoft SQL Server...

What syntax would you use to set two datetime parameters? I want a set a FROM and TO datetime. Specifically I want the @From parameter to be set to 0700 of the current date and the @To set at 1900 of the current date.

DECLARE @From as Datetime
DECLARE @To as Datetime

SET @From=????
SET @To=????

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-08 : 02:28:23
[code]
DECLARE @From as Datetime
DECLARE @To as Datetime

SET @From=DATEADD(hh,7,DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0))
SET @To=DATEADD(hh,19,DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0))
...
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

stharish
Starting Member

43 Posts

Posted - 2012-01-08 : 11:13:25
Perfect! Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-08 : 11:29:04
see this to understand similar date generation techniques

http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -