ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 11th, 2004, 05:39 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
Displaying information from this year/last year

I have a few pages on my site that display information for the last three months.

At the moment, I'm using this code:

Code:
<%
for iLoop = 1 to 2  			
sql = "SELECT P.productTitle, P.pCode, P.author, P.publicationDate, S.subject FROM products P, subject S WHERE
month(P.publicationDate) = month(now)-" & iLoop & " AND year(P.publicationDate) = year(now) AND P.subject = S.subjectID AND
prodStatus = 'Published' ORDER BY P.pCode"  			
set rs=Server.CreateObject("ADODB.recordset")  			
set rs=conn.execute(sql)  			
if not (rs.BOF and rs.EOF) then  		   
%>  	  			
<span class="heading3">New titles in <% = MonthName(month(now)-iLoop) & " " & year(now) %></span><br><br>
etc.


This worked fine last year, but now that my 3 months spans 2 years, it's throwing up errors. I can manually change the year from year(now) to 2003 and 2004, but I can't seem to get around the fact that you can't do MonthName(month(now)-iLoop when month(now) is January.
Anyone know a way around this?

Reply With Quote
  #2  
Old January 11th, 2004, 07:12 PM
tomsn tomsn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Dresden, Germany
Posts: 44 tomsn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 9 sec
Reputation Power: 6
Send a message via ICQ to tomsn
hi,

you can use the datediff function for sql

Code:
...WHERE Datediff("m",P.publicationDate, getDate()) < 3...


you'll get all database-items from the last 3 month, without any "for..to..next"

tomsn

Reply With Quote
  #3  
Old January 11th, 2004, 08:01 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
Is there some trick to using quote marks with this function cos I get this error message:

Microsoft VBScript compilation error '800a0401'
Expected end of statement
/education/latest.asp, line 37
sql = "SELECT * FROM products P, media M WHERE Datediff("m",P.publicationDate, Date) < 3 AND M.mediatypeId = P.media AND subject NOT IN (20, 21) AND prodStatus = 'Published' ORDER BY P.publicationDate desc;"


The marker is pointing to the first quote mark in front of the 'm'.

Reply With Quote
  #4  
Old January 12th, 2004, 03:51 AM
tomsn tomsn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Dresden, Germany
Posts: 44 tomsn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 9 sec
Reputation Power: 6
Send a message via ICQ to tomsn
yes...
in asp you mark with quotes marks the start and the end of a string...
to use a quote mark AS string you have to use ""

Code:
...Datediff(""m"",....


tomsn

Reply With Quote
  #5  
Old January 12th, 2004, 05:15 PM
Tyssen Tyssen is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Brisbane
Posts: 129 Tyssen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 31 m 55 sec
Reputation Power: 6
Thumbs up

Using the Datediff function within my select statement kept giving me too few parameters errors, but by setting a variable outside the select statement using DateAdd, I was able to get it working.

Thanks for pointing me in the right direction.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Displaying information from this year/last year


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT