简体   繁体   English

设置ColdFusion变量

[英]Setting a ColdFusion variable

I have a problem setting a variable where I am unable to set a variable as a ColdFusion variable that calculates anything that is less than or equals to 90 days from today as shown below. 我在设置变量时遇到问题,无法将其设置为ColdFusion变量,该变量无法计算从今天起小于或等于90天的任何内容,如下所示。 I am getting an error when I try to set the variable as below: 当我尝试如下设置变量时出现错误:

sLate = now() >= 90 

If I cannot create a variable as above, I would like to compare dates between now, and 90 days before now, and publish the output to a variable. 如果我无法如上所述创建变量,那么我想比较现在和现在之间的90天之间的日期,并将输出发布到变量中。

This code snippet should give you a little heads up on how to work with dates. 此代码段将使您对如何使用日期有所了解。 Note that you may want to strip the time portion out of the dates as you might get unexpected results. 请注意,您可能希望去除日期中的时间部分,因为可能会得到意外的结果。

eg Without striping the time element comparing these values will give you ZERO instead of 1 as expected. 例如,在不剥离时间元素的情况下,比较这些值将得到零而不是预期的1。

<cfset dateA = createDateTime(2014,6,4,0,13,0,0)>
<cfset dateB = createDateTime(2014,6,5,0,1,0,0)>
Result A:#dateDiff("d",dateA,dateB)#<br>

<cfset dateA = createDate(2014,6,4)>
<cfset dateB = createDate(2014,6,5)>
Result B:#dateDiff("d",dateA,dateB)#<br>

Hope this example points you in the right direction. 希望这个例子为您指出正确的方向。

<cfset TODAY = now()>
<cfset pastDate = dateAdd("d",-90,TODAY)>
<cfset myDate = createDate(2014,6,4)>
<cfset pastDays = dateDiff("d",myDate,TODAY)>

<cfoutput>
Today:#TODAY#<br>
90 days before today:#pastDate#<br>
My Date:#myDate#<br>
My Date happened #pastDays# days before today.
</cfoutput>
<cfset sLate=DateAdd("d",-90,now())>

If in cfscript: 如果在cfscript中:
sLate=DateAdd("d",-90,now()); sLate = DateAdd(“ d”,-90,now());

As others have mentioned you are using wrong syntax. 正如其他人提到的那样,您使用了错误的语法。 Also from your last line I understand that you want a value 90 days earlier than now. 另外,从您的最后一行知道,您需要比现在早90天的值。 -90 will give a value 90 days earlier and using 90 will provide value of 90 days later from current day. -90将提供90天前的值,而使用90将提供比当前日期晚90天的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM