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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DatePart Problems

Status
Not open for further replies.

llafretaw

MIS
Oct 2, 2001
64
GB
Hi,
I'm having difficulties with the following line of code which keeps throwing up the error that:

'' is not a recognized DatePart option

The offending line is as folows:

AND t.date between '01/01/' & DatePart('yy', getdate()) AND getdate()

basically I'm trying to say where the date is the 01/01/2002 and the currrent date, and next year it'll be 01/01/2003 and so forth. any help would b appreciated.
 
hello...

i think you just need to remove the single quotes from yy in the datepart function...
and convert datetime to char so you can concatenate the year to your specified month and day...

try this...

AND t.date between '01/01/'+convert(char(4),datepart(yy,getdate())) AND getdate()

you can use the substring function so you do not have to convert datetime to char...

AND t.date between '01/01/'+substring(getdate(),8,4) AND getdate()

hth,
q.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top