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!

Display a week at a time

Status
Not open for further replies.

diggy8

IS-IT--Management
May 24, 2002
35
US
I'm building a time tracking application and I want to display one work week at a time, default being the current week. Any FAQs out there about this?
 
The trick, it seems, would be isolating the current day's position in the week and then figuring this distance from sunday by that date..

Code:
<cfparam name="url.datedistance" default="0">

<Cfset to_day=DayOfWeek(Now())>
<!--- If today is not Sunday (1) subtract the difference between what day it is, and 1 --->
<cfif to_day gt 1>
  <cfset to_diff=to_day-1>
  <cfset to_date=DateAdd("d",-#to_diff#,Now())>
<cfelse>
  <cfset to_date=Now())>
</cfif>

And then you query would look like..

<cfquery...>
  select * from Tracker
   where tDate > #dateAdd(to_date,0-(7+(#url.datedistance#*7)),Now())#
     and tDate < #dateAdd(to_date,0-(#url.datedistance#*7),Now())#
</cfquery>

url.datedistance is the parameter you set to navigate weeks.. IE.. This week is 0.. Last week is 1, the week before is 2, etc.. so your links would look something like...

previous week: WeekNav.cfm?datedistance=#evaluate(url.datedistance+1)#
next week (if they're currently viewing a previous week): WeekNav.cfm?datedistance=#evaluate(url.datedistance-1)#

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Thanks webmigit! I modified this some and ended up using the below code which is exactly what I need!

Code:
<cfparam name="url.datedistance" default="-1">

<Cfset to_day=DayOfWeek(Now())>
<!--- If today is not Sunday (1) subtract the difference between what day it is, and 1 --->
<cfif to_day gt 1>  
  <cfset to_diff=to_day-1>
  <cfset to_date=DateAdd("d",-#to_diff#,Now())>
<cfelse>
  <cfset to_date=Now()>
</cfif>

<cfset to_date = DateAdd("ww", url.datedistance, to_date)>

<cfset dfmt = "mm/dd/yy">
<cfoutput>
	#Dateformat(dateadd("d",0,to_date),dfmt)# - 
    #Dateformat(dateadd("d",6,to_date),dfmt)# 
</cfoutput>
 
Glad to hear.

ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top