Link to home
Start Free TrialLog in
Avatar of Scotto13
Scotto13

asked on

GetDate??

I have a query in SQL server 2005 that I run every day.  Can I change the values below to pull the date from the system rather than having to change them each day?

set @rundate = '2006-04-21'   --  Today
set @startdate = '2006-04-20 12:00:00'  --Yesterday 12 PM
set @enddate = '2006-04-20 12:00:00'  --Today 12 PM

The Start and End dates have to use 12:00 PM

Can I use the GetDate function to set this up??

Please help as this is urgent.

Scotto13
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

I assume that 12 PM means at lunch time, not at midnight...

set @rundate = getdate()
set @startdate = dateadd(hour, -12, convert(datetime, convert(varchar(10), @rundate, 120), 120))
set @enddate = dateadd(day, 1, @startdate )

ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Scotto13
Scotto13

ASKER

Yes, 12 PM is Noon.

Tried is and I get no results. ??
select @today = convert(varchar(10),getdate(),120),
@startDate   =  CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime) -1 ,
@endDate    = CAST(convert(varchar(10),getdate(),120)+' 12:00:00' as datetime)
ok.  that last one works.  
Thanks Aneesh!