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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes, 12 PM is Noon.
Tried is and I get no results. ??
Tried is and I get no results. ??
select @today = convert(varchar(10),getdat e(),120),
@startDate = CAST(convert(varchar(10),g etdate(),1 20)+' 12:00:00' as datetime) -1 ,
@endDate = CAST(convert(varchar(10),g etdate(),1 20)+' 12:00:00' as datetime)
@startDate = CAST(convert(varchar(10),g
@endDate = CAST(convert(varchar(10),g
ASKER
ok. that last one works.
ASKER
Thanks Aneesh!
set @rundate = getdate()
set @startdate = dateadd(hour, -12, convert(datetime, convert(varchar(10), @rundate, 120), 120))
set @enddate = dateadd(day, 1, @startdate )