dbTalk Databases Forums  

getdate() in transact SQL

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss getdate() in transact SQL in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jonathan Crawford
 
Posts: n/a

Default getdate() in transact SQL - 06-27-2005 , 02:04 PM






Hi

"select x from tbl_Y where myDate=GetDate"


I am running a dts and need to filter out todays records.
I have the dates in string format but can convert them to
as date dd/mm/yy but can't filter on GetDate() as this returns
the date and the time.

I can't find a simple way to do this and imagine there must be.

The only way I can get it to work is
"where datediff(d, myDate,GetDate())=0" which seems like overkill

grateful for any pointers

Jonathan





Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: getdate() in transact SQL - 06-27-2005 , 02:25 PM






So you want in TSQL to say what records were processed/tagged with today's
date?
As you have discovered Getdate() returns a date and a time so that won't
help you but you can do something like this

WHERE CONVERT(CHAR(8),DateCol,112) = CONVERT(CHAR(8),Getdate(),112)

OR

if you want the rows from the last 24hours (rolling) then

WHERE DateDiff(hour,DateColFromDB,getdate()) < 24


There are other ways also.


--



Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - You thought DTS was good. here we show you the new stuff.
www.konesans.com - Consultancy from the people who know


"Jonathan Crawford" <jc (AT) jcrawford (DOT) co.uk> wrote

Quote:
Hi

"select x from tbl_Y where myDate=GetDate"


I am running a dts and need to filter out todays records.
I have the dates in string format but can convert them to
as date dd/mm/yy but can't filter on GetDate() as this returns
the date and the time.

I can't find a simple way to do this and imagine there must be.

The only way I can get it to work is
"where datediff(d, myDate,GetDate())=0" which seems like overkill

grateful for any pointers

Jonathan







Reply With Quote
  #3  
Old   
Bill
 
Posts: n/a

Default Re: getdate() in transact SQL - 06-27-2005 , 03:02 PM



use the Convert function to convert getDate to just a date value. (lookup
the function to get the correct parameters for your style of date)

Bill

"Jonathan Crawford" <jc (AT) jcrawford (DOT) co.uk> wrote

Quote:
Hi

"select x from tbl_Y where myDate=GetDate"


I am running a dts and need to filter out todays records.
I have the dates in string format but can convert them to
as date dd/mm/yy but can't filter on GetDate() as this returns
the date and the time.

I can't find a simple way to do this and imagine there must be.

The only way I can get it to work is
"where datediff(d, myDate,GetDate())=0" which seems like overkill

grateful for any pointers

Jonathan







Reply With Quote
  #4  
Old   
Jonathan Crawford
 
Posts: n/a

Default Re: getdate() in transact SQL - 06-29-2005 , 12:27 AM



thanks, that did the trick
jonathan
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
So you want in TSQL to say what records were processed/tagged with today's
date?
As you have discovered Getdate() returns a date and a time so that won't
help you but you can do something like this

WHERE CONVERT(CHAR(8),DateCol,112) = CONVERT(CHAR(8),Getdate(),112)

OR

if you want the rows from the last 24hours (rolling) then

WHERE DateDiff(hour,DateColFromDB,getdate()) < 24


There are other ways also.


--



Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - You thought DTS was good. here we show you the new stuff.
www.konesans.com - Consultancy from the people who know


"Jonathan Crawford" <jc (AT) jcrawford (DOT) co.uk> wrote in message
news:O95Cts0eFHA.2520 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi

"select x from tbl_Y where myDate=GetDate"


I am running a dts and need to filter out todays records.
I have the dates in string format but can convert them to
as date dd/mm/yy but can't filter on GetDate() as this returns
the date and the time.

I can't find a simple way to do this and imagine there must be.

The only way I can get it to work is
"where datediff(d, myDate,GetDate())=0" which seems like overkill

grateful for any pointers

Jonathan









Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.