Print Page | Close Window

sending data to asp page based on date

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=11322
Printed Date: 31 March 2026 at 11:58am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: sending data to asp page based on date
Posted By: DevDevil
Subject: sending data to asp page based on date
Date Posted: 27 July 2004 at 3:01pm
I have a table in SQL Server that has 3 rows, LineID, Information, and Expires. It's for a Church calendar and they want to input the data in bulk for different dates. The Expires is the last date they want to info to show. If today's date is 07/27/2004 and there is a record like LineID - 7, Information - Field Trip, and Expires - 07/26/2004, than it should not be seen today. But, if there is a record like LineID - 8, Information - Teacher Inservice, and Expires - 07/28/2004, then it should be seen as long as 07/28/2004 is <= today's date. Basically as soon as the Expires value is greater than today's date the Information can't be viewed, but the Information with the highest Expires value that is less than today's date is the one that is seen by the users. I've written several scripts that "in my mind" should work... but...



Replies:
Posted By: Semikolon
Date Posted: 28 July 2004 at 7:58am
so, what do you actually want help with?


Posted By: DevDevil
Date Posted: 28 July 2004 at 10:37am

well, i guess i need help with either someone telling me what's wrong with my script or showing me a better way. here's mine...
Set rstMercy = Server.CreateObject("ADODB.Recordset")
strSQL1 = "SELECT Max(LineID) " _
& "AS MaxID From DatedMaterial WHERE " _
& "ViewUntil <= '" & CurrentDateTime & "'"
rstMercy.Open strSQL1, connStr
Set rstMercy2 = Server.CreateObject("ADODB.Recordset")
strSQL2 = "SELECT * FROM DatedMaterial WHERE " _
& "LineID = '" & rstMercy("MaxID") & "'"
rstMercy2.Open strSQL2, connStr



Posted By: dpyers
Date Posted: 28 July 2004 at 11:27am

I'd suggest working out the <= date selection statement before addining the additional criteria perhaps with something like the following...

strSQL1 = "SELECT * FROM DatedMaterial " & _
"WHERE datediff(day, ViewUntil, GETDATE()) <= 0"

The most common error using dates in MSSQL queries is invalid format on input dates The second common error is storing the dates in an invalid format to begin with. - e.g. MMDDYYYY is not a vaild date, MM-DD-YYYY is a valid date. You may want to run a query against the db to print some of the dates and make sure they're what you expect. If this proves to be the problem, check out the IsDate and CDate asp commands.

EDIT: A lot of people don't use date fields at all, they store dates as small text fields formatted as YYYYMMDD or YYYY-MM-DD.



-------------

Lead me not into temptation... I know the short cut, follow me.


Posted By: DevDevil
Date Posted: 28 July 2004 at 12:32pm
I really appreciate the info. After tweaking your suggestion a bit everything works great now. These forums are a great resource.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net