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

creating proper date

Status
Not open for further replies.

LAdProg2005

Programmer
Feb 20, 2006
56
0
0
US
Hello,

i am in need of help again. somehow i am not getting the correct dates to output:(8/16 to 8/22 8/9 to 8/15 8/2 to 8/8 7/26 to 8/1 )

Start and end dates of the week is ok but i am getting confused with the loop i think...

<cfset weeks = 4>

<cfset todayDt = Fix( Now() ) />
<cfset stWeek = (todayDt - DayOfWeek( todayDt ) + 1) />
<cfset endWeek = (todayDt + (7 - DayOfWeek( todayDt ))) />

<cfloop index="i" from="1" to="#weeks#">
<cfset formD = #DateAdd("d", stWeek-(7*i), todayDt)# >
<cfset formDt = #DateAdd("d",endWeek+6-(7*i),todayDt)#>
</cfloop>

thanks
 
There are a few ways to do it.

Code:
<cfset weeks = 4>
 
<cfset today = now() />
<cfset startDate = dateAdd("d", -(DayOfWeek(today)-1), today) />
<cfset endDate = dateAdd("d", (7 - DayOfWeek(today)), today) />

<cfoutput>
 <cfloop index="i" from="1" to="#weeks#">
	startDate = #DateFormat(startDate, "m/d")# 
	endDate = #DateFormat(endDate, "m/d")#<br>
    <cfset startDate =  DateAdd("ww", -1, startDate) >
    <cfset endDate =  DateAdd("ww", -1, endDate)>
</cfloop>
</cfoutput>

BTW, you can lose the extra # signs. They are not needed.

----------------------------------
 
A question though,

index is not being used...

<cfloop index="i" from="1" to="#weeks#">

The index is not being used..i am looping through the date
and populating the table columns...so using above method...it is not putting the dates in column..

any ideas?

thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top