Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1956
  • Last Modified:

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
0
Scotto13
Asked:
Scotto13
  • 3
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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 )

0
 
Aneesh RetnakaranDatabase AdministratorCommented:
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)
0
 
Scotto13Author Commented:
Yes, 12 PM is Noon.

Tried is and I get no results. ??
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
Aneesh RetnakaranDatabase AdministratorCommented:
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)
0
 
Scotto13Author Commented:
ok.  that last one works.  
0
 
Scotto13Author Commented:
Thanks Aneesh!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now