Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statement

Status
Not open for further replies.

stevemarsh99

Technical User
Aug 10, 2005
88
GB
Hey guys,

I would like some sort of added charachter if the field I have outputted from my datababse is within 24hours of my current date?
I have a field that is called dates that is outputed on my page and would it be possible to have an If statement that displays some ' *** ' characters if the date is within 24 hours of the current actual date?

Thanks in advance
Steve
 
Depending on how accurate you need this to be. Your database needs to include the time and then just use a datediff() function to compare them to Now() and output a string. If time isnt totally relevant then just use date() and dateadd() to create the 3 dates involved ie. yesterday/today/tomorrow and compare them against your database date and then decide what your output string is to be.

Cheech

[Peace][Pipe]
 
I am not fussed about the time just need the day before or after really. I am a bit of a newbee at this so please ben patient! :)

So where and what code do I put in and how do I get it to appear in funky style?
 
Paste this code into an asp page(if your using asp) and see what happens when you change the value of myDate
Code:
<%
myDate = "30/09/2005"
myStr = myDate
if (datediff("d", myDate, Date()) = 1) then
myStr = "***"
end if
if (datediff("d", Date(), myDate) = 1) then
myStr = "***"
end if
if (datediff("d", Date(), myDate) = 0) then
myStr = "***"
end if
%>
Mydate = <%=myDate%><br>
myStr = <%=myStr%>

Cheech

[Peace][Pipe]
 
have this in my code and it doesnt like it:

myDate = <%=(rs_ealert.Fields.Item("MAGDATE").Value)%>
myStr = myDate
if (datediff("d", myDate, Date()) = 1) then
myStr = "***"
end if
if (datediff("d", Date(), myDate) = 1) then
myStr = "ONE DAY LEFT"
end if
if (datediff("d", Date(), myDate) = 0) then
myStr = "ONE THE DAY"
end if
if (datediff("d", Date(), myDate) = -1) then
myStr = "late by a day!!!"
end if
%>
Mydate = <%=myDate%><br>
myStr = <%=myStr%></p>

Any thoughts?
 
wrong placement of the vbscript stuff
Code:
<%
myDate = (rs_ealert.Fields.Item("MAGDATE").Value)
myStr = myDate
if (datediff("d", myDate, Date()) = 1) then
myStr = "This means the magdate is yesterday"
end if
if (datediff("d", Date(), myDate) = 1) then
myStr = "ONE DAY LEFT"
end if
if (datediff("d", Date(), myDate) = 0) then
myStr = "ON THE DAY"
end if
if (datediff("d", Date(), myDate) = -1) then
myStr = "late by a day!!!"
end if
%>
Mydate = <%=myDate%><br>
myStr = <%=myStr%></p>

Cheech

[Peace][Pipe]
 
Brill, thank you but how would I use this code to change the appearance of text? Like if it is within a day, it goes red?
 
Also How would I have a section where I would choose an option from a a drop down list and based on that, it clears all the data from certain columns in the database?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top