navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

if/then date() question

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> if/then date() question
Page: [1]
 
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
if/then date() question - 2/25/2006 21:13:10   
I am trying to display a message in my results that reads "Last Week!!" only if a field's data (which is in date format= 2/26/2006) is within six days of today without going over. like it wouldnt display if the field contained the date for yesterday.

here is what ive got but for some reason i cant get it. It either displays it for all of my results or for none of them.


<%IF fp_field(fp_rs,"T2")>(date()-6) THEN response.write("<font color""#FF0000"">Last Weekend!!</font>") end if%>


any ideas on whats wrong??

< Message edited by washurjosh -- 2/25/2006 21:20:58 >
BeTheBall

 

Posts: 6381
Joined: 6/21/2002
From: West Point Utah USA
Status: offline

 
RE: if/then date() question - 2/26/2006 11:16:30   
<%
If DateDiff("d","2/16/2006",DateAdd("d",Date(),-6))>0 Then
Response.write("<font color=""#FF0000"">Last Weekend!!</font>")
End If
%>



_____________________________

Duane

Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.

(in reply to washurjosh)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 2/27/2006 2:43:21   
im not sure i understand what the 2/16/2006 is there for.

(in reply to BeTheBall)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 2/27/2006 3:00:46   
So im really not sure that that is the function that i need. where does it compare it to my database field T2?? and when i entered it it displayed the message for every result.

(in reply to washurjosh)
BeTheBall

 

Posts: 6381
Joined: 6/21/2002
From: West Point Utah USA
Status: offline

 
RE: if/then date() question - 2/27/2006 10:28:44   
Sorry, the 2/16 date was what I used in testing. You would use:

<%
If DateDiff("d",FP_Field(fp_rs,"T2"),DateAdd("d",Date(),-6))>0 Then
Response.write("<font color=""#FF0000"">Last Weekend!!</font>")
End If
%>


_____________________________

Duane

Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.

(in reply to washurjosh)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 2/27/2006 19:05:58   
Duane,

Thanks so much, ill test it when i get home tonight. You are wonderful and i do that all the time!!


Josh

(in reply to BeTheBall)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 2/27/2006 22:23:41   
ok, that didnt work. I added it and now it doesnt show "last week" on any of the results.

whats next?

(in reply to washurjosh)
BeTheBall

 

Posts: 6381
Joined: 6/21/2002
From: West Point Utah USA
Status: offline

 
RE: if/then date() question - 2/27/2006 22:35:45   
Can you post the code you have so far. The whole page may help me get a better idea.

_____________________________

Duane

Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.

(in reply to washurjosh)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: if/then date() question - 2/27/2006 23:17:05   
I would expect this code to work, however you need to ensure your database value matches the expected date comparison
eg : Is FP_Field(fp_rs,"T2") the same format as date() ?

<% 
IF cdate(FP_Field(fp_rs,"T2")) > (date()-6) THEN
Response.write("<font color=""#FF0000"">Last Week!</font>") 
End if
%>


_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to BeTheBall)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 2/28/2006 0:03:32   
here is the code for the whole page, i hope it helps. Also i am using the format 2/12/2006 in T2 which, in my mind, is the same as Date() since i tested it by doing a response.write on date() and it came up with that format. So.......maybe my format is not equal and im being tricked by the computer!!!


<div align="center">
					<table border="0" cellpadding="0" style="border-collapse: collapse" width="100%" id="table49">
						<tr>
							<td valign="top">
								<div align="center">
									<table border="0" cellpadding="5" style="border-collapse: collapse" width="97%" id="table50">
										<tr>
											<td width="312">
											<p align="center">
								<font color="#000000"> <font face="Tahoma"><span lang="en-us"><b>Shows 
								On Now</b></span></font></font></td>
											<td>
											<p align="center">
											<span lang="en-us"><b>
											<font face="Tahoma" size="1">
											<a href="uploadshowinfo.htm">Upload 
											Additional Show</a></font></b></span></td>
										</tr>
										<tr>
											<td colspan="2">
											<hr></td>
										</tr>
									</table>
								</div>
								<div align="left">
								<table id="table51" width="100%" cellpadding="0" cellspacing="0">
									<tbody>
<!--#include file="_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM Results WHERE T1<=Date() AND T2>=Date() ORDER BY T2 ASC"
fp_sDefault=""
fp_sNoRecords="<tr><td colspan=7 align=""LEFT"" width=""100%"">No records returned.</td></tr>"
fp_sDataConn="shows"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice=""
fp_sMenuValue=""
fp_sColTypes="&ID=3&theatre=202&showtitle=202&opendate=202&closedate=202&showpicture=202&S1=203&boxofficenumber=202&T1=202&T2=202&T3=202&T4=202&T5=202&T6=202&T7=202&T8=202&T9=202&Remote_computer_name=202&User_name=202&Browser_type=202&Timestamp=135&synopsis=203&"
fp_iDisplayCols=7
fp_fCustomQuery=False
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<tr>
											<td bgcolor="#6699FF" rowspan="2" width="210" align="center">
											<a style="text-decoration: none; color: #800000" href="<% =FP_Field(fp_rs,"T4")%>"><b><font face="Times New Roman" color="#800000" size="2">
											
<br>


<% =FP_Field(fp_rs,"theatre")%><% =FP_Field(fp_rs,"T3")%>


											<span lang="en-us"><br>
</span></font><i><font face="Times New Roman" color="#800000" size="2">




<% =FP_Field(fp_rs,"showtitle")%>

</font><font face="Verdana" size="2" color="#800000"><br>
</font></i></b>


<img border="0" src="<% =FP_Field(fp_rs,"showpicture")%>">






</a>






<b><font face="Verdana" size="2" color="#FFFFFF"><br>



</font><font face="Tahoma" color="#FFFFFF" size="2">


<% =FP_Field(fp_rs,"opendate")%>


<span lang="en-us"> 
											- </span>
<% =FP_Field(fp_rs,"closedate")%>
<br>
<% 
If DateDiff("d",FP_Field(fp_rs,"T2"),DateAdd("d",Date(),-6))>0 Then 
Response.write("<font color=""#FF0000"">Last Weekend!!</font>") 
End If 
%> </font></b></td>							
											
											<td>
											</td>
										</tr>
										<tr>
											<td align="center">
											<div align="center">
												<table border="0" style="border-collapse: collapse" width="100%" id="table54" cellpadding="0" cellspacing="4">
													<tr>
														<td>
														<div align="center">
<p align="center"><b>
											<font face="Verdana" size="2">
										
										
										 

										<% =FP_Field(fp_rs,"synopsis")%>
										</font></b></div>
											<p align="center"><b>
											<font face="Verdana" size="2">
											<% =FP_Field(fp_rs,"theatre")%>

											<br>
											Box Office: </span>
											<% =FP_Field(fp_rs,"boxofficenumber")%>
</font></b></td>
													</tr>
												</table>
											</div>
											</td>
										</tr>
										<tr>
											<td align="center" colspan="2">
								<hr width="95%"></td>
										</tr>
<!--#include file="_fpclass/fpdbrgn2.inc"-->
</tbody>
								</table>
								</div>
							</td>
							<td width="241" valign="top">
							<div align="right">
			<table border="0" width="210" id="table52" cellpadding="5" style="border-collapse: collapse">
							<tr>
								<td width="200" align="center">
								<font color="#000000"> 
								<span lang="en-us"><b><font face="Tahoma">
								Upcoming Shows</font></b></span></font></td>
							</tr>
							<tr>
								<td>
								<hr></td>
							</tr>
							</table></div>
							<div align="right">
								<table width="210" cellspacing="0" cellpadding="0" id="table53">
									<tbody>
<!--#include file="_fpclass/fpdblib.inc"-->
<% if 0 then %>
<SCRIPT Language="JavaScript">
document.write("<div style='background: yellow; color: black;'>The Database Results component on this page is unable to display database content. The page must have a filename ending in '.asp', and the web must be hosted on a server that supports Active Server Pages.</div>");
</SCRIPT>
<% end if %>
<%
fp_sQry="SELECT * FROM Results WHERE T1 > Date() ORDER BY T1"
fp_sDefault=""
fp_sNoRecords="<tr><td colspan=22 align=""LEFT"" width=""100%"">No Shows Currently Upcoming</td></tr>"
fp_sDataConn="shows"
fp_iMaxRecords=256
fp_iCommandType=1
fp_iPageSize=0
fp_fTableFormat=True
fp_fMenuFormat=False
fp_sMenuChoice="ID"
fp_sMenuValue="ID"
fp_sColTypes="&ID=3&theatre=202&showtitle=202&opendate=202&closedate=202&showpicture=202&S1=203&boxofficenumber=202&T1=202&T2=202&T3=202&T4=202&T5=202&T6=202&T7=202&T8=202&T9=202&Remote_computer_name=202&User_name=202&Browser_type=202&Timestamp=135&synopsis=203&"
fp_iDisplayCols=22
fp_fCustomQuery=True
BOTID=0
fp_iRegion=BOTID
%>
<!--#include file="_fpclass/fpdbrgn1.inc"-->
<tr>
											<td bgcolor="#6699FF">
											<p align="center"><b>
											<font face="Times New Roman" color="#800000" size="2">
											

											<a style="text-decoration: none; color: #800000" href="<% =FP_Field(fp_rs,"T4")%>">
											

<% =FP_Field(fp_rs,"theatre")%><% =FP_Field(fp_rs,"T3")%>


											<span lang="en-us"><br>
</span></font><i><font face="Times New Roman" color="#800000" size="2">




<% =FP_Field(fp_rs,"showtitle")%>

</font><font face="Verdana" size="2" color="#800000"><br>
</font></i></b>





<img border="0" src="<% =FP_Field(fp_rs,"showpicture")%>">






</a>






<b><font face="Verdana" size="2" color="#FFFFFF"><br>



</font><font face="Tahoma" color="#FFFFFF" size="2">


<% =FP_Field(fp_rs,"opendate")%>


<span lang="en-us"> 
											- </span>
<% =FP_Field(fp_rs,"closedate")%>
</font></b></td>
										</tr>
										<tr>
											<td>
								<hr></td>
										</tr>
<!--#include file="_fpclass/fpdbrgn2.inc"-->
									</tbody>
								</table>
								</div>
							</td>
						</tr>
					</table>
				</div>

(in reply to Spooky)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: if/then date() question - 2/28/2006 0:58:58   
And my code failed?

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to washurjosh)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 2/28/2006 1:47:31   
when i tried your code, spooky, it displayed the message for all the results.

here is the url

http://www.theschmoogle.com/current.asp


(in reply to Spooky)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: if/then date() question - 2/28/2006 14:01:28   
What is the result when you do this for each record? <%=FP_Field(fp_rs,"T2")%>

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to washurjosh)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 3/1/2006 4:25:59   
Im not sure what you mean.


The T2 fields contain different dates in the format of 3/12/2006, some say 3/19/2006, etc. Something tells me DATE() is not in this format??

Again i am highly confused. any help is appreciated. Thanks!

(in reply to Spooky)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 3/1/2006 4:47:16   
And on another issue. my sql for the same database results is supposed to weed out my shows that have already passed the opening date "T1" and before the ending date "T2" but i just noticed today (which is 3/1/2006 and that is what DATE() wrote) it spit out a result for the T1 date of 3/4/2006 .


honestly im getting the idea that using the date format of m/d/yyyy is a bad idea and that "date()" doesnt recognize it and when i have something like 3/4/2006 it is very diffrent to the computer than 3/04/2006. which format does date recognize and how to ensure that the database and the results know im talking about a specific date????


(in reply to washurjosh)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: if/then date() question - 3/1/2006 13:51:17   
Add this code to the very top of your page :
Session.LCID 			= 1033

Function DateFormat(dt)
DateFormat = year(dt)&"/"&left("00",2-len(month(dt)))&month(dt)&"/"&left("00",2-len(day(dt)))&day(dt) &" " & formatdatetime(dt,4)
End Function


Now try this code :

<% 
IF DateFormat(FP_Field(fp_rs,"T2")) > DateFormat(date()-6) THEN
Response.write("<font color=""#FF0000"">Last Week!</font>") 
End if
%>


_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to washurjosh)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 3/2/2006 5:50:19   
i added the code to the top of the page like you requested. I put it in my <head> field in asp brackets. then i tried the code, however it now responds "last week" for every entry. the date function you created seems like a good idea.

I dont have many entries at this point, under 50 so if i need to totally reformat the way i enter dates in T2 initially so things run smoother, not a problem, but i dont know what format to change it to, or if thats what i should do at all.

It seems my intuitive-ness has run out . thanks for all your help spook and everyone!

(in reply to Spooky)
washurjosh

 

Posts: 66
Joined: 1/18/2006
Status: offline

 
RE: if/then date() question - 3/9/2006 3:36:48   
I guess i stumped everyone. HA ...well i will keep on the search!

(in reply to washurjosh)
Spooky

 

Posts: 26606
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: if/then date() question - 3/9/2006 15:30:36   
As part of your testing, its still best to response.write FP_Field(fp_rs,"T2") and also date() so that you can visually compare the difference.
Not stumped, just hard to troubleshoot from afar ;-)

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to washurjosh)
Page:   [1]

All Forums >> Web Development >> ASP and Database >> if/then date() question
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts