PDA

View Full Version : Time


The Wizzard
12-27-2002, 01:39 AM
Hi, I dont really know what to call this topic :confused:

But my question is:

I have something in my database.

And this object has a picture with it. Now, after, lets say, 5 days, I want to make the picture change to something else, and stay that way...

How can this be done?

Thanks!

Mhtml
12-27-2002, 04:02 AM
This is where the datediff() function will come in handy.. Here's an example.


<%
MyPic = "images/smile.jpg"
k = datediff("d", "27/12/02", date())
if k => 5 then
'change the pic
MyPic = "images/frown.jpg"
else
'don't do anything
MyPic = MyPic
end if
%>
<img src="<%=MyPic%>" />


Lets look at the datediff() part of it first..
You'll notice the d, it stands for DAY and MUST be surrounded by quotes or it will think it is a variable.

By using the DAY we are telling it to find the difference between the 27/12/02 and today in days.

Now the two dates need to be there so that we can find the difference between them in DAYS. It obviously will not matter which order they are in because it is going to be the same either way.

The Wizzard
12-27-2002, 05:09 PM
Thanks M!

Works, for now... We have to wait and see in a few days ;)

whammy
12-28-2002, 12:34 AM
It should work, that's one of the nice date features of not only VBScript, but SQL Server as well. DATEDIFF() is your friend! :)

If you're using SQL Server, you should also be able to schedule a "job" which can also update your picture in the database depending upon what you specify... also, look up the DateDiff() function on google or MSDN, there are a lot of very useful parameters you can use. :D