Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using getdate() in a proc

Status
Not open for further replies.

jwestmore

Programmer
May 27, 2003
14
US
I'm inserting records into a table on a daily basis from 3 source tables that are updated in real-time. I want to capture records entered between midnight to 11:59pm of the previous day.

Somthing like

INSERT INTO destination_table

SELECT * FROM source_tables
WHERE entry_date = dateadd(day,-1,getdate())

Problem is, the entry_date field and getdate() both include times as well as dates. Any suggestions on how to use getdate() excluding the time portion and simply returning the date?

Thanks in advance,
Jon
 
Why use DATEADD? Test this:

WHERE entry_date = getdate()-1

-SQLBill
 
You can use this to return the previous days date as a datetime data type, with the time set to 00:00:00

WHERE entry_date = dateadd(dd,datediff(dd,0,getdate()),-1)
 
I think we all missed your point. We are showing you ways to use just the date in your WHERE clause. You want your RESULTS to have just the date.

If you want just the date returned from a datetime column, you can't use:
SELECT *

You will need to list out your columns (the bold part shows how to get JUST the date returned):

SELECT somecolumn, someothercolumn, convert(char(10),entry_date,1) as MyDate
FROM source_tables
WHERE entry_date = getdate()-1

Let us know if that's what you are looking for.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top