codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  database and time date exire  eddieeagle at 14:14 on Monday, November 01, 2004
 

I have a database with articles that expire after a certain date and this works fine. I would also like to make them expire at the date at a certain time.



Does anyone know how to do this?


Thanks in advance

Eddie

  Re: database and time date exire  tgreer at 01:03 on Thursday, November 04, 2004
 

What database? What platform? What language? How do you get them to "expire" currently? What exactly do you mean by "expire"?



  Re: database and time date exire  eddieeagle at 23:29 on Thursday, November 04, 2004
 

Hi , the language is ASP the database is Access or SQL server.

In the database i have the table articles.
this contains the following
ID (autonumber)
Title (text)
Article (memo)
Created (date) standard date format
Expiredate (datetime) shortdate 01-11-2004
Expiretime (datetime) shorttime 15:30
Using the date and time shown above the article should not display on the page as the date is now 05-11-2004

But I also wanted it not to display on the page at the date 01-11-2004 at 15:31


I hope this is info enough

Regards
Eddie_Eagle

  Re: database and time date exire  tgreer at 00:29 on Friday, November 05, 2004
 

Could you also give us the SELECT statement and/or Stored Procedure you're currently using?

<Added>

If you are responsible for the database design, you should combine the expire date and expire time fields into a single field of type "datetime". Then, your code that performs the query can compare to a single field.

If you can't change the database, you need to combine the two fields in your query, using the "add" operator, which is the plus sign "+", or even better, the DATEADD function.

I'd have to see your existing query/stored proc to show you a modified version.



  Re: database and time date exire  eddieeagle at 16:54 on Friday, November 05, 2004
 

Hi
Thanks
I have the code here:

Set rs = oConn.Execute("Select * from cases Where active <> 0 order by caseTitle")
Do While Not rs.Eof
ExpireDate=FormatDateTime(rs("expiredate"),vbShortDate)
DateNow=FormatDateTime(Date(), vbShortDate)
viewData=datediff("D",DateNow,ExpireDate)
If viewData >= 0 OR rs("expire") = 0 Then

' Display the data
Response.Write "<p>" rs("created") & "</p>"
Response.Write "<p>" rs("title") & "</p>"
Response.Write "<p>" rs("article") & "</p>"

rs.MoveNext ' go to next record
Loop
I have control of the database so I could change the expire date field.

Thanks in advance
regards
Eddie

  Re: database and time date exire  tgreer at 17:23 on Friday, November 05, 2004
 

Then that's definitely the way to go... store an entire timestamp, date plus time, in a single field in the database.

I would also modify your query. Add a where clause to only select non-expired records:


Set rs = oConn.Execute(@"Select * from cases Where (active <> 0
and ExpireDate > " +
DateNow=FormatDateTime(Date(), vbGeneralDate) +
") order by caseTitle")


Don't trust that code, I don't know what you need to do to make ASP return a complete datetime. In .NET it's "System.DateTime".



  Re: database and time date exire  eddieeagle at 22:27 on Saturday, November 06, 2004
 

Hi
Thanks for your help

I changed the field expiredate to a general date in the database and changed the sql to this.

Set rs = oConn.Execute("Select * from cases Where (active <> 0 and ExpireDate > Now()) order by caseTitle")

This worked the way that I needed.
I have only tried this in access and wil try it in SQL server, but I know that SQL server treats date/time differnt than access so I am not sure it will work


Best regards
Eddie








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: database and time date exire
•  Re: Column count
•  Re: Page Load
•  Re: error in using
•  how to acheive this in C++
•  Re: Testing file for type of data
•  Re: javascript and jsp
•  Re: all page security with a cookie
•  Re: calling functions from JS-generated HTMLpage


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2004