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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date Range Variables?

Author  Topic 

jun0
Starting Member

32 Posts

Posted - 2013-03-08 : 06:31:02
Hello,

I need to set up a stored procedure that runs each day and select data from a tale based on a specific date range e.g

lastoccurrence >= 'midnight the previous day' and lastoccurrence < 'midnight last night'

Obviously I can't hard code the dates in here, as that would really defeat the object of the stored procedure, so how do I go aout doing this so that the dates entered will always be between midnight he previous day and 12:00 last night? (sorry if the time range I need is a bit ambiguous, hope you understand what I'm after)..

thansk you!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-08 : 06:36:43
use getdate() function for that

lastoccurrence >= dateadd(dd,datediff(dd,0,getdate()),-1) and lastoccurrence < dateadd(dd,datediff(dd,0,getdate()),0)



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

Go to Top of Page
   

- Advertisement -