Skip to main content
Inspiring
April 27, 2007
Question

Datediff question

  • April 27, 2007
  • 4 replies
  • 325 views
I have the following code:

<cfset DateList=dateformat("7/24/2006","mmmm d,yyyy")>
<cfset CurrDate=dateformat(now(),"mmmm d,yyyy")>

<cfloop list="#DateList#" index="cDate" delimiters=",">
<cfif datediff("ww",#CurrDate#,#cDate#) gt 1>
<span style="color:#FF0000;"><cfoutput>#cDate#</cfoutput><br /></span>
<else>
<span style="color:#00CC00;"><cfoutput>#cDate#</cfoutput><br /></span>
</cfif>
</cfloop>

I'm trying to get the date to display in 1 color if the time between now and
the date listed is more than a week. My problem is that its return the date
in color, but both colors.

Also, if I wanted to have a loop within a loop, so a loop that counts from 1
to 7, and then within that loop, another list loop that lists 1 date per
item, how can I do that? I'm a little rusty on my loop stuff!

Thanks!
Steve


    This topic has been closed for replies.

    4 replies

    Inspiring
    April 28, 2007
    Yep, I discovered the <cfelse> later, thanks for pointing that part out! :)

    "cflover00" <webforumsuser@macromedia.com> wrote in message
    news:f0u02k$jmi$1@forums.macromedia.com...
    > Replace "<else>" with "<cfelse>". And here is a simple loop within a loop:
    >
    > <cfloop from="1" to="7" index="i">
    > <cfloop from="1" to="4" index="j">
    > <cfoutput>#dateformat(dateadd("d", i + j, now()), "mm/dd/yy")#</cfoutput>
    > </cfloop>
    > <br>
    > </cfloop>
    >
    >


    Inspiring
    April 28, 2007
    Steve Grosz wrote:

    > <cfset DateList=dateformat("7/24/2006","mmmm d,yyyy")>
    ....
    > <cfloop list="#DateList#" index="cDate" delimiters=",">

    your DateList list is "July 24,2006", your cDate index will be only
    "July 24" since you are using "," as list delimiter in your loop. thus
    cDate is not a proper DATE.

    > <cfif datediff("ww",#CurrDate#,#cDate#) gt 1>

    hence datediff should not work (or will work incorrectly), trying to
    compare "April 29,2007" and "July 24" values...


    --
    Azadi Saryev
    Sabai-dee.com
    Vientiane, Laos
    http://www.sabai-dee.com
    Inspiring
    April 28, 2007
    Briefly,
    Dateformat returns a string, not a date, so date functions may or may not work.
    You set your datelist variable to a single value and then looped through it.
    The variable cdate is probably undefined. It's not defined anywhere in your code sample.
    Participating Frequently
    April 27, 2007
    Replace "<else>" with "<cfelse>". And here is a simple loop within a loop:

    <cfloop from="1" to="7" index="i">
    <cfloop from="1" to="4" index="j">
    <cfoutput>#dateformat(dateadd("d", i + j, now()), "mm/dd/yy")#</cfoutput>
    </cfloop>
    <br>
    </cfloop>