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

Hours to go? 1

Status
Not open for further replies.

bluesauceuk

Programmer
Jan 1, 2001
73
GB
Hello,

I am trying to get a countdown to a time in hours.

The time I want to countdown to is Fridays at 22:00 (10pm)

Is there a way I can count down to this town only displaying whole hours.. eg 36 hrs to go

Also, when it gets to 22:00 and until 03:00 (3am sat) I would like it to say... "on now!"

then after 3.00 am i would like it to count down again until 10pm the nect friday in hours?

I have no idead how to start this? dates really confuse me.

Thanks

Mark

 
The following is probably not the most efficient way of doing what you need, but hopefully you can get some ideas from it to get you going.

btw: Test the heck out of it.. I haven't ran it yet, so I'm sure I've overlooked something - I agree.. dates can get really confusing.

<!---
Array that holds the amount of days to add to today.
The index represents the Cardinal day of the week; ie. 1=Sunday and 7=Saturday.
The value of the array (0-6) represents the difference of days from today and the coming up Friday;
Creating this array will save us from running condtional statements when creating the locCountDownDate variable --->
<cfset arrWeekArrange=ArrayNew(1)>
<cfset arrWeekArrange[7]=6>
<cfset arrWeekArrange[1]=5>
<cfset arrWeekArrange[2]=4>
<cfset arrWeekArrange[3]=3>
<cfset arrWeekArrange[4]=2>
<cfset arrWeekArrange[5]=1>
<cfset arrWeekArrange[6]=0>

<!--- Create a timestamp for the coming up Friday --->
<cfset locCountDownDate=DateAdd(&quot;d&quot;,arrWeekArrange[DayOfWeek(now())],now())>
<cfset locCountDownDate=CreateDateTime(Year(locCountDownDate),month(locCountDownDate),day(locCountDownDate),&quot;22&quot;,&quot;00&quot;,&quot;00&quot;)>

<!--- Calculate the hour difference between now and Friday 22:00 --->
<cfset locHoursToGo=DateDiff(&quot;h&quot;,now(),locCountDownDate)>


<cfoutput>
<!--- If 'now' is Friday or Saturday between the hours of 22:00 and 3, display 'ON NOW' --->
<cfif (DayOfWeek(now()) IS (6 OR 7) AND Hour(now()) GTE 22) AND (DayOfWeek(now()) IS (6 OR 7) AND Hour(now()) LTE 3)>
On now
<cfelse>
#locHoursToGo# hours to go
</cfif>
</cfoutput>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top