在ColdFusion中,我可以看到下面的代码,但是它似乎不起作用。我要确保仅在有效的开始日期和结束日期在范围内时才应用折扣,请参见下文。

if (
  DATEDIFF("d", discount.ValidFrom(), now()) >= 0 
  AND  
  DATEDIFF("d", now(), discount.ValidTo()) <= 0
){
   // ALL OK Accept Discount
}
    else 
{
   // Discount is no Longer Valid boo!
}

最佳答案

您的逻辑有些偏离。现在你要回来

if ({positive_number} and {negative_number})


返回false。您应该检查dateDiff(“ d”,今天,Discount.to())是否也> = 0。

<cfscript>
    local = {};
    local.start = createDate( 2011, 10, 01 );
    local.end = createDate( 2011, 10, 30 );
    local.today = now();
    local.valid = false;

    if ( (dateDiff("d", local.start, local.today) >= 0) 
            AND (dateDiff("d", local.today, local.end) >= 0) ){
        local.valid = true;
    }
</cfscript>

<cfoutput>
x < z: #dateDiff("d", local.start, local.today) GTE 0#
<hr />
z < y: #dateDiff("d", local.today, local.end) GTE 0#
<hr />
Valid: #local.valid#
</cfoutput>

08-04 02:18