Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2003, 02:40 PM
Authorized User
 
Join Date: Oct 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date Calculations

Hey all,

Just like to say first off: Thanks to everyone, i couldn't survive without you guys.

Okay here is my problem. I have a set of scripts for posting online ads. One particular script is supposed to find all of the records that are past 30 days old and delete them. I figured with would be easy, but no luck so far. Here is my script:

<%

Dim query


Set dbGlobalWeb = Server.CreateObject("ADODB.Connection")
dbGlobalWeb.ConnectionTimeout = 15
dbGlobalWeb.CommandTimeout = 30
dbGlobalWeb.Open "DBQ=" & Server.MapPath("emarket.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20 ;", "username", "password"


query = "DELETE * FROM listings WHERE TO_DAYS(NOW()) - TO_DAYS(DatePosted) > '30'"


dbGlobalWeb.Execute query
%>

<center>
Cleanup completed successfully!<br><br>
<a href="admin_cp.asp">Back to Control Panel </a>
</center>

<%
dbGlobalWeb.Close
Set con = Nothing
%>


But I keep getting errors about the TO_DAYS in the query. I used that from a reference on this page: http://www.phpbuilder.com/mail/php-db/2001051/0084.php. I know it was for php, but I thought it would translate to ASP. Any help is greatly appreciated.

Michael W. Vollmer
__________________
Michael W. Vollmer
 
Old October 14th, 2003, 10:38 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

Hi
First Your Write this query to global.asa
'''''''''''''''''''''''''''''''''''''''''''''
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Application_OnStart
        Application("Cnn_ConnectionString") = "DSN=emarket;DBQ=c:\database\emarket.mdb;DriverId= 281;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"
        Application("Cnn_ConnectionTimeout") = 15
        Application("Cnn_CommandTimeout") = 30
        Application("Cnn_CursorLocation") = 3
        Application("Cnn_RuntimeUserName") = ""
        Application("Cnn_RuntimePassword") = ""
End Sub
</SCRIPT>
'''''''''''''''''''''''''''''''
and make a DSN

1.Open the ODBC icon in your Control Panel.
2.Choose the System DSN tab.
3.Click on Add in the System DSN tab.
4.Select the Microsoft Access Driver. Click Finish.
5.In the next screen, click Select to locate the database.
6.Give the database a Data Source Name (DSN).
7.Click OK.
'''''''''''''''''''''''''''''
then u can write a asp page
<%
set cnn=Server.CreateObject("ADODB.connection")
cnn.Open Application("Cnn_connectionstring")
query = "DELETE * FROM listings WHERE TO_DAYS(NOW()) - TO_DAYS(DatePosted) > '30'"
cnn.Execute(query)
%>




S.S
 
Old October 15th, 2003, 08:45 AM
Authorized User
 
Join Date: Oct 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I cannot use a DSN connection in my pages. I have everything else working fine without one. Is a DSN the only way that this will work? I have to have a DSN-less connection due to the way the server I am using is setup.

Michael W. Vollmer
 
Old October 15th, 2003, 09:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

No, you don't need a DSN. You just need to know about the DateDiff function!

As an aside, you really should use the Access OLEDB driver from ASP (see http://www.able-consulting.com/ADO_Conn.htm for examples), not the ODBC driver which you are using.
 
Old October 15th, 2003, 10:48 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

hello mvollmer
yes you need to use DateDiff function
(TO_DAYS(NOW()) - TO_DAYS(DatePosted) > '30'")
try to use DateDiff function.

surendran





Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Calculations edove ASP.NET 2.0 Basics 0 March 30th, 2007 07:05 AM
Date Calculations scourge SQL Server 2000 9 May 11th, 2006 05:08 AM
Positioning Calculations rit01 ASP.NET 1.x and 2.0 Application Design 3 February 22nd, 2006 03:10 PM
Date Calculations Stu_morris40 Infopath 0 November 1st, 2005 11:53 AM
Wierd Date Calculations Steven Access 2 December 16th, 2003 07:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.