Display Date Dependant Content

Displaying content depending on what the current date value is a powerful and effective tool that adds value to any website. Whether it is to showcase a limited time offer, or to “automatically” update pages with new content while you’re miles away. The following code repeats the process to three times to demonstrate the full effects of date dependent content. The content is set to display only on 12/31/2014 and shows a preview and how many days until the content will show up and an after view after expiration.
' The following for next loop is used to demonstrate
' how this code will work on three different dates
' The varible the_date should be set to date() to retrieve 
' the current date when implemented 
for count = 1 to 3

if count = 1 then  the_date=#12/30/2014#

if count = 2 then the_date=#12/31/2014#

if count = 3 then the_date=#01/01/2015#

 start_date= #12/31/2014#
 expiration_date = #01/01/2015#
 Response.Write "Start Date =" & start_date &" End Date =" & expiration_date & " Today =" & the_date & "<br />"

if start_date <= the_date then

	if expiration_date - the_date <= 0 then 
		Response.Write "Content has expired <u>on</u> "& expiration_date

		Response.Write "Content will appear <u>for</u>" & expiration_date - the_date " & more day(s)"
	end if
	Response.Write "Content will appear <u>in</u>" & abs(the_date - start_date)

end if
The Result is something like:
Start Date =12/31/2014
End Date =1/1/2015
Today =12/30/2014

If today's date was 12/30/2014 the content will appear in 1 more day(s)
If today's date was 12/31/2014 the content will appear for 1 more day(s)
If today's date was 1/1/2015 the content has expired.

asp date dependent content automatic updates updates ASP ADO VBScript tutorial authoring howto reference examples samples source code demos tips

Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site