|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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'. |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Displaying information from this year/last year |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|