Print Page | Close Window

Select right(strDate,4) question..

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=9506
Printed Date: 31 March 2026 at 11:22pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Select right(strDate,4) question..
Posted By: mobious
Subject: Select right(strDate,4) question..
Date Posted: 03 February 2004 at 1:06pm

Hello,

I am trying to write a select statement that would select the year out of a date field on my MsSQL db..

Something like this..

sql="SELECT * FROM tblDailyB WHERE right(dbDate, 4) = '2003' ORDER BY dbDate asc;"

This isnt working.. Is there a way to select the year from a date field?




Replies:
Posted By: MorningZ
Date Posted: 03 February 2004 at 3:20pm

sql="SELECT * FROM tblDailyB WHERE DatePart(yyyy,dbDate) = 2003 ORDER BY dbDate asc;"

Note that DatePart returns a number, so the tics around 2003 aren't used



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: mobious
Date Posted: 04 February 2004 at 11:58am

That did the trick.. Thanks for the help..

In all of the books I have read about ASP I have never seen that..




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net