Need help for programing for condition using date.

R

riyaz

i am creating a asp page where i want to display records based upon the
following condition ,i have tried but i cant get it.
condition:

check the current date is with in the limits of the fdate & tdate ,if yes
then display corresponding row of records.

this is My table(display) :

fdate tdate Announcement Event Discussion

4/10/2006 4/30/2006 sampletext1 sampletext2 sampletext3
5/1/2006 5/30/2006 phrase1 phrase2 phrase3

i want to display the records for the period of days ,Dynamically it should
change records after the date end.

for example: today is 4/22/2006 , so page must display the first row as it
satisfies the condition..


i have wrote the code for displaying one field,but it does not work.

my code is:

<%
Dim cn,rs
Dim sDate ' current date from the page

Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

cn.Provider = "MicroSoft.jet.OLEDB.4.0"
cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\webap\test.mdb"
rs.Open "display",cn,3,3

sDate=Request.Form("Tcdate")

%>

<%

Do While Not rs.EOF

If sDate>=rs("fdate") AND sDate<=rs("tdate") Then

Response.Write rs("Announcement")

end if

rs.MoveNext
loop
%>

<%

rs.close
set rs=nothing

%>

please help me to correct my code

thanks & regards
Niyaz
 
S

Stefan B Rusynko

Your form date is being treated as a string
Change
sDate=Request.Form("Tcdate")
To
IF IsDate(Request.Form("Tcdate")) Then sDate=Cdate(Request.Form("Tcdate"))

--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
To find the best Newsgroup for FrontPage support see:
http://www.frontpagemvps.com/FrontPageNewsGroups/tabid/53/Default.aspx
_____________________________________________


|i am creating a asp page where i want to display records based upon the
| following condition ,i have tried but i cant get it.
| condition:
|
| check the current date is with in the limits of the fdate & tdate ,if yes
| then display corresponding row of records.
|
| this is My table(display) :
|
| fdate tdate Announcement Event Discussion
|
| 4/10/2006 4/30/2006 sampletext1 sampletext2 sampletext3
| 5/1/2006 5/30/2006 phrase1 phrase2 phrase3
|
| i want to display the records for the period of days ,Dynamically it should
| change records after the date end.
|
| for example: today is 4/22/2006 , so page must display the first row as it
| satisfies the condition..
|
|
| i have wrote the code for displaying one field,but it does not work.
|
| my code is:
|
| <%
| Dim cn,rs
| Dim sDate ' current date from the page
|
| Set cn = Server.CreateObject("ADODB.Connection")
| Set rs = Server.CreateObject("ADODB.Recordset")
|
| cn.Provider = "MicroSoft.jet.OLEDB.4.0"
| cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
| Source=C:\Inetpub\wwwroot\webap\test.mdb"
| rs.Open "display",cn,3,3
|
| sDate=Request.Form("Tcdate")
|
| %>
|
| <%
|
| Do While Not rs.EOF
|
| If sDate>=rs("fdate") AND sDate<=rs("tdate") Then
|
| Response.Write rs("Announcement")
|
| end if
|
| rs.MoveNext
| loop
| %>
|
| <%
|
| rs.close
| set rs=nothing
|
| %>
|
| please help me to correct my code
|
| thanks & regards
| Niyaz
|
|
 
R

riyaz

i have changed according to your code still i am not getting any records & it
dont display any error message also

this is my table i tested with this code:

fdate tdate Announcement Event Discussion
4/10/2006 4/30/2006 phrase1 phrase2 phrase3
1/5/2006 10/5/2006 text1 text2 text3

this is d code:

<%

Dim cn,rs
Dim sDate
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")

cn.Provider = "MicroSoft.jet.OLEDB.4.0"
cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Inetpub\wwwroot\webap\test.mdb"
rs.Open "display",cn,3,3

IF IsDate(Request.Form("Tcdate")) Then sDate=Cdate(Request.Form("Tcdate"))
%>

<%
Do While Not rs.EOF

If sDate>=rs("fdate") AND sDate<=rs("tdate") Then

Response.Write rs("Announcement")

end if

rs.MoveNext
loop
%>

<%
rs.close
set rs=nothing
%>


This is code by which i am getting the current date:

<input type="hidden" name="Tcdate" size="14" value="<%=Date()%>">

please help me to do this, any problem with database..

thanks & regards
Niyaz

Stefan B Rusynko said:
Your form date is being treated as a string
Change
sDate=Request.Form("Tcdate")
To
IF IsDate(Request.Form("Tcdate")) Then sDate=Cdate(Request.Form("Tcdate"))

--

_____________________________________________
SBR @ ENJOY (-: [ Microsoft MVP - FrontPage ]
"Warning - Using the F1 Key will not break anything!" (-;
To find the best Newsgroup for FrontPage support see:
http://www.frontpagemvps.com/FrontPageNewsGroups/tabid/53/Default.aspx
_____________________________________________


|i am creating a asp page where i want to display records based upon the
| following condition ,i have tried but i cant get it.
| condition:
|
| check the current date is with in the limits of the fdate & tdate ,if yes
| then display corresponding row of records.
|
| this is My table(display) :
|
| fdate tdate Announcement Event Discussion
|
| 4/10/2006 4/30/2006 sampletext1 sampletext2 sampletext3
| 5/1/2006 5/30/2006 phrase1 phrase2 phrase3
|
| i want to display the records for the period of days ,Dynamically it should
| change records after the date end.
|
| for example: today is 4/22/2006 , so page must display the first row as it
| satisfies the condition..
|
|
| i have wrote the code for displaying one field,but it does not work.
|
| my code is:
|
| <%
| Dim cn,rs
| Dim sDate ' current date from the page
|
| Set cn = Server.CreateObject("ADODB.Connection")
| Set rs = Server.CreateObject("ADODB.Recordset")
|
| cn.Provider = "MicroSoft.jet.OLEDB.4.0"
| cn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
| Source=C:\Inetpub\wwwroot\webap\test.mdb"
| rs.Open "display",cn,3,3
|
| sDate=Request.Form("Tcdate")
|
| %>
|
| <%
|
| Do While Not rs.EOF
|
| If sDate>=rs("fdate") AND sDate<=rs("tdate") Then
|
| Response.Write rs("Announcement")
|
| end if
|
| rs.MoveNext
| loop
| %>
|
| <%
|
| rs.close
| set rs=nothing
|
| %>
|
| please help me to correct my code
|
| thanks & regards
| Niyaz
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top