getting all the records in the last month from a d

Results 1 to 2 of 2

Thread: getting all the records in the last month from a d

  1. #1
    Join Date
    Dec 1969

    Default getting all the records in the last month from a d

    Hi,<BR><BR>I am having problems with a script I have written to return and display all the records in my database that have a date of: (current date of the asp page calling the recordset (- 1 month)).<BR><BR>Here is the code:<BR>&#060;%<BR>Dim MonthDate<BR>&#039;set MonthDate as the current date minus 1 month from now<BR>MonthDate = DateSerial(Year(Date), Month(Date)- 1, Day(Date))<BR>&#039;Recordset as rsNews<BR>Set rsNews = Server.CreateObject("ADODB.Recordset")<BR>&#039;ge t articles where AnoDate is equal to or greater than MonthDate (so ones in the last month only)<BR>strSQL = "SELECT Article FROM tblFiles WHERE AnoDate &#062;= "&MonthDate&" ORDER BY Article DESC"<BR>rsNews.Open strSQL, HomeConn, 3<BR>%&#062;<BR>&#039;some html<BR>&#039; print MonthDate to ensure the right date is returned<BR>The Month date is:&#060;%=MonthDate%&#062;<BR>&#039; cycle through the recordset<BR>&#060;%Do While Not rsNews.EOF<BR> Response.Write "&#060;font face=Verdana color=blue&#062;" & rsNews("Article") & "&#060;/font&#062;" & "<BR>"<BR> rsNews.MoveNext<BR> Loop<BR> rsNews.Close<BR> Set rsNews=Nothing<BR> %&#062;<BR><BR>Any help would be appreciated - I think it is something in the way that MS Access looks at dates.<BR><BR>Thanks in advance!<BR><BR>Neil<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: getting all the records in the last month from

    For Access:<BR><BR>SELECT *<BR>FROM Table<BR>WHERE dateField &#062;= DateAdd(&#039;month&#039;, -1, Date())<BR><BR>For SQL Server:<BR>SELECT *<BR>FROM Table<BR>WHERE dateField &#062;= DateAdd(month, -1, GETDATE())<BR><BR>You might need to work with the DateAdd function, but that should get you almost there.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts