Help for DateDiff

Results 1 to 5 of 5

Thread: Help for DateDiff

  1. #1
    Chunkey Pandey Guest

    Default Help for DateDiff

    I couldn&#039;t figure out how do i use datediff: I want all record whose date of entry is more than 30 days from today.<BR><BR>I am trying datediff("d", Now, 30). I dont know whether this is right. Can somebody illustrate pleaseeeee

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Use dateadd <eop>


  3. #3
    Chunkey Pandey Guest

    Default RE: Use dateadd <eop>

    Please can u illustrate, show me how do i use that function. I have simple request that I need to search all record with dates more than 30 days from today

  4. #4
    Reggie Guest

    Default RE: Help for DateDiff

    This will give you all the records that were added in the last month. If you want it to be 30 days, change the very first line to what the comment says.<BR>&#060;%<BR>monthAgo=DateAdd("m", -1, Now) &#039;monthAgo=DateAdd("d", -30, Now)<BR>SQL_query = "SELECT * from myTable WHERE date_added BETWEEN &#039;"&monthAgo&"&#039; AND &#039;"&now()&"&#039;"<BR>set RS = MyConn.execute (SQL_query)<BR>While not rs.eof<BR>response.write rs("id")&"<BR>"<BR>rs.movenext<BR>wend<BR>%&#062;< BR>

  5. #5
    Join Date
    Dec 1969

    Default Yes, yes, nod, nod...

    ...but we might note that Access (to pick one example) will let you do this without any calculations outside of the SQL:<BR><BR>SQL_query = "SELECT * from myTable WHERE date_added BETWEEN DateAdd(&#039;m&#039;,-1,Date()) AND Date()"<BR><BR>SQL Server is almost the same:<BR><BR>SQL_query = "SELECT * from myTable WHERE date_added BETWEEN DateAdd(m,-1,GetDate()) AND GetDate()"<BR><BR>[note no quotes around the m that means month]<BR><BR>Other DBs have similar capabilities.<BR><BR>ONE CAUTION: Both the ASP version shown by Reggie and the SQL Server version shown just above will go back *exactly* one the *second*. So anything added on the day one month prior to today that was added before the current time-of-day will *not* be included.<BR><BR><BR><BR>

Posting Permissions

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