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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple date dependant image problem. 1

Status
Not open for further replies.

PTmon

IS-IT--Management
Mar 8, 2001
284
US
Hi, I need to rotate a image between 4 images, one for sprint, summer, fall, and winter. Basically January 1 through March 31 one image1 is displayed, april 1 through June 31 image2 is displayed etc. I'm having trouble figuring out the best way to do this. i don't want to have to set up a table just for that, and I'm having trouble with how to format a IF statement for this.
TIA for any help you can give to get me pointed in the right direction.
PT
 
If you name your images
Code:
season1.gif
season2.gif
season3.gif
season4.gif

then simply dynamically build the IMG tag using ColdFusions Quarter() function to determine the quarter the current date is in
Code:
<CFOUTPUT>
<img src=&quot;/images/season#Quarter(Now())#.gif&quot; ...>
</CFOUTPUT>

would do it.

Of course you could get as complicated as you want... building a list of image names if naming them season1... season4 isn't kosher... like
Code:
<CFSET mySeasonImagesList = &quot;winter.gif,spring.gif,summer.gif,fall.gif&quot;>

<CFSET currentSeasonImage = ListGetAt(&quot;#mySeasonImagesList #&quot;,Quarter(Now()))>

<CFOUTPUT><img src=&quot;/images/#currentSeasonImage#&quot; ...></CFOUTPUT>

Or, since the seasons don't actually fall exactly on the Quarters (Jan 1st - Mar 31, etc), you might actually want to use weeks of the year, rather than quarters.

Like
Code:
<CFSWITCH expression=&quot;#Week(Now())#&quot;>
<CFCASE value=&quot;1,2,3,4,5,6,7,8,9,10,11,52&quot;>
	<CFSET todaysSeason = &quot;winter&quot;>
</CFCASE>
<CFCASE value=&quot;12,13,14,15,16,17,18,19,20,21,22,23,24,25&quot;>
	<CFSET todaysSeason = &quot;spring&quot;>
</CFCASE>
<CFCASE value=&quot;26,27,28,29,30,31,32,33,34,35,36,37,38&quot;>
	<CFSET todaysSeason = &quot;summer&quot;>
</CFCASE>
<CFDEFAULTCASE>
	<CFSET todaysSeason = &quot;fall&quot;>
</CFDEFAULTCASE>
</CFSWITCH>

<CFOUTPUT><img src=&quot;/images/#todaysSeason#.gif&quot; ...></CFOUTPUT>

Don't trust my math in the case statement. Doublecheck the week values on your own.

-Carl
 
Thanks!
<CFOUTPUT>
<img src=&quot;/images/season#Quarter(Now())#.gif&quot; ...>
</CFOUTPUT>

That is so much simpler than what I was trying to do!
Thanks for your time.
PT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top